Rev 538 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
538 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | ------------ |
||
23 | CVS : $Id: crtwin.c,v 1.1 2004-03-29 18:31:40 mauro Exp $ |
||
24 | |||
25 | File: $File$ |
||
26 | Revision: $Revision: 1.1 $ |
||
27 | Last update: $Date: 2004-03-29 18:31:40 $ |
||
28 | ------------ |
||
29 | |||
30 | Author: Gerardo Lamastra |
||
31 | Date: 9/5/96 |
||
32 | |||
33 | File: CrtWin.C |
||
34 | Revision: 1.1g |
||
35 | |||
36 | Text windowing functions for S.Ha.R.K. |
||
37 | |||
38 | **/ |
||
39 | |||
40 | /* |
||
41 | * Copyright (C) 2000 Paolo Gai |
||
42 | * |
||
43 | * This program is free software; you can redistribute it and/or modify |
||
44 | * it under the terms of the GNU General Public License as published by |
||
45 | * the Free Software Foundation; either version 2 of the License, or |
||
46 | * (at your option) any later version. |
||
47 | * |
||
48 | * This program is distributed in the hope that it will be useful, |
||
49 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
50 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
51 | * GNU General Public License for more details. |
||
52 | * |
||
53 | * You should have received a copy of the GNU General Public License |
||
54 | * along with this program; if not, write to the Free Software |
||
55 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
56 | * |
||
57 | */ |
||
58 | |||
59 | //#include <string.h> |
||
60 | //#include <cons.h> |
||
61 | |||
62 | #include <kernel/kern.h> |
||
1689 | fabio | 63 | #include <arch/string.h> |
538 | mauro | 64 | #include <drivers/crtwin.h> |
65 | |||
66 | #define CUPS1 201 /* Definizione caratteri per */ |
||
67 | #define LOR1 205 /* La cornice delle varie */ |
||
68 | #define CUPD1 187 /* Finestre */ |
||
69 | #define LVR1 186 |
||
70 | #define CDWS1 200 |
||
71 | #define CDWD1 188 |
||
72 | |||
73 | #define CUPS2 218 |
||
74 | #define LOR2 196 |
||
75 | #define CUPD2 191 |
||
76 | #define LVR2 179 |
||
77 | #define CDWS2 192 |
||
78 | #define CDWD2 217 |
||
79 | |||
80 | void win_init(WIN *w, int x, int y, int dx, int dy) |
||
81 | { |
||
82 | w->x = x; |
||
83 | w->y = y; |
||
84 | w->dx = dx; |
||
85 | w->dy = dy; |
||
86 | |||
87 | w->px = 0; |
||
88 | w->py = 0; |
||
89 | } |
||
90 | |||
91 | void win_clear(WIN *w) |
||
92 | { |
||
93 | _clear(' ',WHITE,w->x+1,w->y+1,w->x+w->dx-1,w->y+w->dy-1); |
||
94 | } |
||
95 | |||
96 | void win_scroll(WIN *w) |
||
97 | { |
||
98 | _scroll(WHITE,w->x+1,w->y+1,w->x+w->dx-1,w->y+w->dy-1); |
||
99 | } |
||
100 | |||
101 | void win_frame(WIN *w,BYTE bcol,BYTE fcol,char *title,BYTE type) |
||
102 | { |
||
103 | unsigned char var,var2,len; |
||
104 | register int i; |
||
105 | char cus,lv,cud,lo,cds,cdd,cl = ((bcol << 4) | fcol); |
||
106 | len = strlen(title); |
||
107 | switch(type) { |
||
108 | case 1 : cus = CUPS1; lv = LVR1; cud = CUPD1; |
||
109 | lo = LOR1; cds = CDWS1; cdd = CDWD1; |
||
110 | break; |
||
111 | case 2 : cus = CUPS2; lv = LVR2; cud = CUPD2; |
||
112 | lo = LOR2; cds = CDWS2; cdd = CDWD2; |
||
113 | break; |
||
114 | default : cus = lv = cud = lo = cds = cdd = 32; |
||
115 | break; |
||
116 | } |
||
117 | for (i = w->x+1; i < w->x+w->dx; i++) { |
||
118 | putc_xy(i,w->y,cl,lo); |
||
119 | putc_xy(i,w->y+w->dy,cl,lo); |
||
120 | } |
||
121 | putc_xy(w->x+w->dx,w->y,cl,cud); |
||
122 | putc_xy(w->x,w->y,cl,cus); |
||
123 | |||
124 | if (title != NULL) { |
||
125 | var2 = w->x+(w->dx/2) - len/2 - 1; |
||
126 | var = 0; |
||
127 | putc_xy(var2,w->y,cl,'['); |
||
128 | puts_xy(var2+1,w->y,cl,title); |
||
129 | putc_xy(var2+len+1,w->y,cl,']'); |
||
130 | } |
||
131 | |||
132 | for (i = w->y+1; i < w->y+w->dy; i++) { |
||
133 | putc_xy(w->x,i,cl,lv); |
||
134 | putc_xy(w->x+w->dx,i,cl,lv); |
||
135 | } |
||
136 | putc_xy(w->x,w->y+w->dy,cl,cds); |
||
137 | putc_xy(w->x+w->dx,w->y+w->dy,cl,cdd); |
||
138 | } |
||
139 | |||
140 | void win_puts(WIN *w1, char *s) |
||
141 | { |
||
142 | unsigned pos; |
||
143 | char c; |
||
144 | static unsigned short scan_x,x,y; |
||
145 | WIN w; |
||
146 | |||
147 | w = *w1; |
||
148 | x = w.px + w.x + 1; |
||
149 | y = w.py + w.y + 1; |
||
150 | |||
151 | pos = 2*(y*80 + x); |
||
152 | while (*s != '\0') { |
||
153 | c = *s++; |
||
154 | switch (c) { |
||
155 | case '\t' : x += 8; |
||
156 | if (x >= w.x+w.dx) { |
||
157 | x = w.x+1; |
||
158 | if (y == w.y+w.dy-1) win_scroll(&w); |
||
159 | else y++; |
||
160 | } else { |
||
161 | scan_x = w.x+1; |
||
162 | while ((scan_x+8) < x) scan_x += 8; |
||
163 | x = scan_x; |
||
164 | } |
||
165 | pos = 2*(x + 80*y); |
||
166 | break; |
||
167 | case '\n' : y += (x - w.x - 1) / w.dx + 1; |
||
168 | x = w.x + 1; |
||
169 | while (y > (w.y+w.dy-1)) { |
||
170 | win_scroll(&w); |
||
171 | y--; |
||
172 | } |
||
173 | pos = 2*(x + 80*y); |
||
174 | break; |
||
175 | case '\b' : putc_xy(x-1,y,WHITE,' '); |
||
176 | break; |
||
177 | default : putc_xy(x,y,WHITE,c); |
||
178 | pos += 2; |
||
179 | x++; |
||
180 | if (x >= w.x + w.dx) { |
||
181 | x = w.x+1; |
||
182 | if (y >= (w.y + w.dy - 1)) win_scroll(&w); |
||
183 | else y++; |
||
184 | pos = 2*(x + 80*y); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | if (x > (w.x+w.dx-1)) { |
||
189 | y += (x - w.x - 1) / w.dx; |
||
190 | x = (x - w.x - 1) % w.dx + w.x + 1; |
||
191 | while (y >= (w.y+w.dy)) { |
||
192 | win_scroll(&w); |
||
193 | y--; |
||
194 | } |
||
195 | } |
||
196 | w1->px = x - w.x - 1; |
||
197 | w1->py = y - w.y - 1; |
||
198 | } |
||
199 | |||
200 | /*int win_gets(WIN *w, char *s,int len) |
||
201 | { |
||
202 | int strpos = 0,lungh = 0; |
||
203 | int x,y,tx,ty,i; |
||
204 | BYTE flag = FALSE; |
||
205 | KEY_EVT c; |
||
206 | |||
207 | x = w->px + w->x + 1; |
||
208 | y = w->py + w->y + 1; |
||
209 | s[0] = 0; |
||
210 | place(x,y); |
||
211 | |||
212 | while (!flag) { |
||
213 | keyb_getcode(&c,BLOCK); |
||
214 | if (isScanCode(c) && (c.scan == LEFT_KEY) && (strpos > 0)) { |
||
215 | strpos--; |
||
216 | x--; |
||
217 | if (x <= w->x) { |
||
218 | x = w->x + w->dx - 1; |
||
219 | y--; |
||
220 | if (y <= w->y) y = w->y + 1; |
||
221 | } |
||
222 | place(x,y); |
||
223 | } |
||
224 | else if (isScanCode(c) && (c.scan == RIGHT_KEY) && s[strpos] != 0) { |
||
225 | strpos++; |
||
226 | x++; |
||
227 | if (x >= (w->x + w->dx)) { |
||
228 | x = w->x + 1; |
||
229 | y++; |
||
230 | if (y >= (w->y + w->dy)) { |
||
231 | y--; |
||
232 | win_scroll(w); |
||
233 | } |
||
234 | } |
||
235 | place(x,y); |
||
236 | } |
||
237 | switch (c.ascii) { |
||
238 | case ENTER : |
||
239 | if (!isScanCode(c)) flag = TRUE; |
||
240 | break; |
||
241 | case BACKSPACE : |
||
242 | if (!isScanCode(c) && (strpos > 0)) { |
||
243 | strpos--; |
||
244 | x--; |
||
245 | if (x <= w->x) { |
||
246 | x = w->x + w->dx - 1; |
||
247 | y --; |
||
248 | if (y <= w->y) y = w->y + 1; |
||
249 | } |
||
250 | tx = x; ty = y; |
||
251 | i = strpos; |
||
252 | while (s[i] != 0) { |
||
253 | s[i] = s[i+1]; |
||
254 | putc_xy(tx,ty,WHITE,s[i]); |
||
255 | i++; |
||
256 | tx++; |
||
257 | if (tx >= w->x + w->dx) { |
||
258 | tx = w->x + 1; |
||
259 | ty++; |
||
260 | } |
||
261 | } |
||
262 | lungh--; |
||
263 | } |
||
264 | place(x,y); |
||
265 | break; |
||
266 | case DELETE : |
||
267 | if (s[strpos] != 0) lungh--; |
||
268 | tx = x; ty = y; |
||
269 | i = strpos; |
||
270 | while (s[i] != 0) { |
||
271 | s[i] = s[i+1]; |
||
272 | putc_xy(tx,ty,WHITE,s[i]); |
||
273 | i++; |
||
274 | tx++; |
||
275 | if (tx >= w->x + w->dx) { |
||
276 | tx = w->x; |
||
277 | ty++; |
||
278 | } |
||
279 | } |
||
280 | place(x,y); |
||
281 | break; |
||
282 | default : |
||
283 | if (!isScanCode(c)) { |
||
284 | i = lungh; |
||
285 | while (i > strpos) { |
||
286 | s[i] = s[i-1]; |
||
287 | i--; |
||
288 | } |
||
289 | s[lungh+1] = 0; |
||
290 | s[strpos] = c.ascii; |
||
291 | strpos++; |
||
292 | lungh++; |
||
293 | if (lungh == (len - 1)) flag = TRUE; |
||
294 | tx = x; |
||
295 | ty = y; |
||
296 | i = strpos - 1; |
||
297 | while (s[i] != 0) { |
||
298 | putc_xy(tx,ty,WHITE,s[i]); |
||
299 | tx++; |
||
300 | i++; |
||
301 | if (tx >= (w->x + w->dx)) { |
||
302 | tx = w->x + 1; |
||
303 | ty++; |
||
304 | if (ty >= (w->y + w->dy)) { |
||
305 | ty--; |
||
306 | y--; |
||
307 | win_scroll(w); |
||
308 | } |
||
309 | } |
||
310 | } |
||
311 | x++; |
||
312 | if (x >= (w->x + w->dx)) { |
||
313 | x = w->x + 1; |
||
314 | y++; |
||
315 | } |
||
316 | } |
||
317 | place(x,y); |
||
318 | break; |
||
319 | } |
||
320 | |||
321 | } |
||
322 | w->px = 0; |
||
323 | w->py = y - w->y; |
||
324 | if (w->py >= w->dy - 1) { |
||
325 | w->py--; |
||
326 | win_scroll(w); |
||
327 | } |
||
328 | return(lungh); |
||
329 | } |
||
330 | |||
331 | static void cons_end(void *arg) |
||
332 | { |
||
333 | set_active_page(0); |
||
334 | set_visual_page(0); |
||
335 | } |
||
336 | |||
337 | static void cons_change(KEY_EVT *k) |
||
338 | { |
||
339 | //k.scan -= KEY_1; |
||
340 | set_visual_page(k->scan-KEY_1); |
||
341 | } |
||
342 | |||
343 | void screen_init(void) |
||
344 | { |
||
345 | KEY_EVT k; |
||
346 | int i; |
||
347 | |||
348 | k.flag = ALTR_BIT; |
||
349 | for (i = 0; i < 8; i++) { |
||
350 | k.ascii = '1' + i; |
||
351 | k.scan = KEY_1 + i; |
||
352 | keyb_hook(k,cons_change); |
||
353 | } |
||
354 | sys_atrunlevel(cons_end,NULL,RUNLEVEL_AFTER_EXIT); |
||
355 | }*/ |