Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 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.1.1 2002-03-29 14:12:49 pj Exp $
24
 
25
 File:        $File$
26
 Revision:    $Revision: 1.1.1.1 $
27
 Last update: $Date: 2002-03-29 14:12:49 $
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>
63
#include <ll/string.h>
64
#include <drivers/keyb.h>
65
#include <drivers/keycode.h>
66
#include <drivers/crtwin.h>
67
 
68
#define CUPS1   201        /* Definizione caratteri per */
69
#define LOR1    205        /* La cornice delle varie    */
70
#define CUPD1   187        /* Finestre                  */
71
#define LVR1    186
72
#define CDWS1   200
73
#define CDWD1   188
74
 
75
#define CUPS2   218
76
#define LOR2    196
77
#define CUPD2   191
78
#define LVR2    179
79
#define CDWS2   192
80
#define CDWD2   217
81
 
82
void win_init(WIN *w, int x, int y, int dx, int dy)
83
{
84
    w->x = x;
85
    w->y = y;
86
    w->dx = dx;
87
    w->dy = dy;
88
 
89
    w->px = 0;
90
    w->py = 0;
91
}
92
 
93
void win_clear(WIN *w)
94
{
95
    _clear(' ',WHITE,w->x+1,w->y+1,w->x+w->dx-1,w->y+w->dy-1);
96
}
97
 
98
void win_scroll(WIN *w)
99
{
100
    _scroll(WHITE,w->x+1,w->y+1,w->x+w->dx-1,w->y+w->dy-1);
101
}
102
 
103
void win_frame(WIN *w,BYTE bcol,BYTE fcol,char *title,BYTE type)
104
{
105
    unsigned char var,var2,len;
106
    register int i;
107
    char cus,lv,cud,lo,cds,cdd,cl = ((bcol << 4) | fcol);
108
    len = strlen(title);
109
    switch(type) {
110
               case 1 : cus = CUPS1; lv = LVR1;   cud = CUPD1;
111
                        lo = LOR1;   cds = CDWS1; cdd = CDWD1;
112
                        break;
113
               case 2 : cus = CUPS2; lv = LVR2;   cud = CUPD2;
114
                        lo = LOR2;   cds = CDWS2; cdd = CDWD2;
115
                        break;
116
               default : cus = lv = cud = lo = cds = cdd = 32;
117
                         break;
118
    }
119
    for (i = w->x+1; i < w->x+w->dx; i++) {
120
        putc_xy(i,w->y,cl,lo);
121
        putc_xy(i,w->y+w->dy,cl,lo);
122
    }
123
    putc_xy(w->x+w->dx,w->y,cl,cud);
124
    putc_xy(w->x,w->y,cl,cus);
125
 
126
    if (title != NULL) {
127
        var2 = w->x+(w->dx/2) - len/2 - 1;
128
        var = 0;
129
        putc_xy(var2,w->y,cl,'[');
130
        puts_xy(var2+1,w->y,cl,title);
131
        putc_xy(var2+len+1,w->y,cl,']');
132
    }
133
 
134
    for (i = w->y+1; i < w->y+w->dy; i++) {
135
        putc_xy(w->x,i,cl,lv);
136
        putc_xy(w->x+w->dx,i,cl,lv);
137
    }
138
    putc_xy(w->x,w->y+w->dy,cl,cds);
139
    putc_xy(w->x+w->dx,w->y+w->dy,cl,cdd);
140
}
141
 
142
void win_puts(WIN *w1, char *s)
143
{
144
    unsigned pos;
145
    char c;
146
    static unsigned short scan_x,x,y;
147
    WIN w;
148
 
149
    w = *w1;
150
    x = w.px + w.x + 1;
151
    y = w.py + w.y + 1;
152
 
153
    pos = 2*(y*80 + x);
154
    while (*s != '\0') {
155
        c = *s++;
156
        switch (c) {
157
            case '\t' : x += 8;
158
                        if (x >= w.x+w.dx) {
159
                            x = w.x+1;
160
                            if (y == w.y+w.dy-1) win_scroll(&w);
161
                            else y++;
162
                        } else {
163
                            scan_x = w.x+1;
164
                            while ((scan_x+8) < x) scan_x += 8;
165
                            x = scan_x;
166
                        }
167
                        pos = 2*(x + 80*y);
168
                        break;
169
            case '\n' : y += (x - w.x - 1) / w.dx + 1;
170
                        x = w.x + 1;
171
                        while (y > (w.y+w.dy-1)) {
172
                            win_scroll(&w);
173
                            y--;
174
                        }
175
                        pos = 2*(x + 80*y);
176
                        break;
177
            case '\b' : putc_xy(x-1,y,WHITE,' ');
178
                        break;
179
            default   : putc_xy(x,y,WHITE,c);
180
                        pos += 2;
181
                        x++;
182
                        if (x >= w.x + w.dx) {
183
                            x = w.x+1;
184
                            if (y >= (w.y + w.dy - 1)) win_scroll(&w);
185
                            else y++;
186
                            pos = 2*(x + 80*y);
187
                        }
188
        }
189
    }
190
    if (x > (w.x+w.dx-1)) {
191
        y += (x - w.x - 1) / w.dx;
192
        x = (x - w.x - 1) % w.dx + w.x + 1;
193
        while (y >= (w.y+w.dy)) {
194
            win_scroll(&w);
195
            y--;
196
        }
197
    }
198
    w1->px = x - w.x - 1;
199
    w1->py = y - w.y - 1;
200
}
201
 
202
int win_gets(WIN *w, char *s,int len)
203
{
204
    int strpos = 0,lungh = 0;
205
    int x,y,tx,ty,i;
206
    BYTE flag = FALSE;
207
    KEY_EVT c;
208
 
209
    x = w->px + w->x + 1;
210
    y = w->py + w->y + 1;
211
    s[0] = 0;
212
    place(x,y);
213
 
214
    while (!flag) {
215
        keyb_getcode(&c,BLOCK);
216
        if (isScanCode(c) && (c.scan == LEFT_KEY) && (strpos > 0)) {
217
            strpos--;
218
            x--;
219
            if (x <= w->x) {
220
                x = w->x + w->dx - 1;
221
                y--;
222
                if (y <= w->y) y = w->y + 1;
223
            }
224
            place(x,y);
225
        }
226
        else if (isScanCode(c) && (c.scan == RIGHT_KEY) && s[strpos] != 0) {
227
            strpos++;
228
            x++;
229
            if (x >= (w->x + w->dx)) {
230
                x = w->x + 1;
231
                y++;
232
                if (y >= (w->y + w->dy)) {
233
                    y--;
234
                    win_scroll(w);
235
                }
236
            }
237
            place(x,y);
238
        }
239
        switch (c.ascii) {
240
            case ENTER :
241
                if (!isScanCode(c)) flag = TRUE;
242
                break;
243
            case BACKSPACE :
244
                if (!isScanCode(c) && (strpos > 0)) {
245
                    strpos--;
246
                    x--;
247
                    if (x <= w->x) {
248
                        x = w->x + w->dx - 1;
249
                        y --;
250
                        if (y <= w->y) y = w->y + 1;
251
                    }
252
                    tx = x; ty = y;
253
                    i = strpos;
254
                    while (s[i] != 0) {
255
                        s[i] = s[i+1];
256
                        putc_xy(tx,ty,WHITE,s[i]);
257
                        i++;
258
                        tx++;
259
                        if (tx >= w->x + w->dx) {
260
                            tx = w->x + 1;
261
                            ty++;
262
                        }
263
                    }
264
                    lungh--;
265
                }
266
                place(x,y);
267
                break;
268
            case DELETE :
269
                if (s[strpos] != 0) lungh--;
270
                tx = x; ty = y;
271
                i = strpos;
272
                while (s[i] != 0) {
273
                    s[i] = s[i+1];
274
                    putc_xy(tx,ty,WHITE,s[i]);
275
                    i++;
276
                    tx++;
277
                    if (tx >= w->x + w->dx) {
278
                        tx = w->x;
279
                        ty++;
280
                    }
281
                }
282
                place(x,y);
283
                break;
284
            default :
285
                if (!isScanCode(c)) {
286
                    i = lungh;
287
                    while (i > strpos) {
288
                        s[i] = s[i-1];
289
                        i--;
290
                    }
291
                    s[lungh+1] = 0;
292
                    s[strpos] = c.ascii;
293
                    strpos++;
294
                    lungh++;
295
                    if (lungh == (len - 1)) flag = TRUE;
296
                    tx = x;
297
                    ty = y;
298
                    i = strpos - 1;
299
                    while (s[i] != 0) {
300
                        putc_xy(tx,ty,WHITE,s[i]);
301
                        tx++;
302
                        i++;
303
                        if (tx >= (w->x + w->dx)) {
304
                            tx = w->x + 1;
305
                            ty++;
306
                            if (ty >= (w->y + w->dy)) {
307
                                ty--;
308
                                y--;
309
                                win_scroll(w);
310
                            }
311
                        }
312
                    }
313
                    x++;
314
                    if (x >= (w->x + w->dx)) {
315
                        x = w->x + 1;
316
                        y++;
317
                    }
318
                }
319
                place(x,y);
320
                break;
321
        }
322
 
323
    }
324
    w->px = 0;
325
    w->py = y - w->y;
326
    if (w->py >= w->dy - 1) {
327
        w->py--;
328
        win_scroll(w);
329
    }
330
    return(lungh);
331
}
332
 
333
static void cons_end(void *arg)
334
{
335
    set_active_page(0);
336
    set_visual_page(0);
337
}
338
 
339
static void cons_change(KEY_EVT *k)
340
{
341
  /* MG */
342
  //k.scan -= KEY_1;
343
  set_visual_page(k->scan-KEY_1);
344
}
345
 
346
void screen_init(void)
347
{
348
    KEY_EVT k;
349
    int i;
350
 
351
    k.flag = ALTR_BIT;
352
    for (i = 0; i < 8; i++) {
353
        k.ascii = '1' + i;
354
        k.scan = KEY_1 + i;
355
        keyb_hook(k,cons_change);
356
    }
357
    sys_atrunlevel(cons_end,NULL,RUNLEVEL_AFTER_EXIT);
358
}