1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/*-
* Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer as
* the first lines of this file unmodified.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _DEV_SYSCONS_SCTERMVAR_H_
#define _DEV_SYSCONS_SCTERMVAR_H_
/*
* building blocks for terminal emulator modules.
*/
static __inline void sc_term_ins_line(scr_stat *scp, int y, int n, int ch,
int attr, int tail);
static __inline void sc_term_del_line(scr_stat *scp, int y, int n, int ch,
int attr, int tail);
static __inline void sc_term_ins_char(scr_stat *scp, int n, int ch,
int attr);
static __inline void sc_term_del_char(scr_stat *scp, int n, int ch,
int attr);
static __inline void sc_term_col(scr_stat *scp, int n);
static __inline void sc_term_row(scr_stat *scp, int n);
static __inline void sc_term_up(scr_stat *scp, int n, int head);
static __inline void sc_term_down(scr_stat *scp, int n, int tail);
static __inline void sc_term_left(scr_stat *scp, int n);
static __inline void sc_term_right(scr_stat *scp, int n);
static __inline void sc_term_up_scroll(scr_stat *scp, int n, int ch,
int attr, int head, int tail);
static __inline void sc_term_down_scroll(scr_stat *scp, int n, int ch,
int attr, int head, int tail);
static __inline void sc_term_clr_eos(scr_stat *scp, int n, int ch, int attr);
static __inline void sc_term_clr_eol(scr_stat *scp, int n, int ch, int attr);
static __inline void sc_term_tab(scr_stat *scp, int n);
static __inline void sc_term_backtab(scr_stat *scp, int n);
static __inline void sc_term_respond(scr_stat *scp, u_char *s);
static __inline void sc_term_gen_print(scr_stat *scp, u_char **buf, int *len,
int attr);
static __inline void sc_term_gen_scroll(scr_stat *scp, int ch, int attr);
static __inline void
sc_term_ins_line(scr_stat *scp, int y, int n, int ch, int attr, int tail)
{
if (tail <= 0)
tail = scp->ysize;
if (n < 1)
n = 1;
if (n > tail - y)
n = tail - y;
sc_vtb_ins(&scp->vtb, y*scp->xsize, n*scp->xsize, ch, attr);
mark_for_update(scp, y*scp->xsize);
mark_for_update(scp, scp->xsize*tail - 1);
}
static __inline void
sc_term_del_line(scr_stat *scp, int y, int n, int ch, int attr, int tail)
{
if (tail <= 0)
tail = scp->ysize;
if (n < 1)
n = 1;
if (n > tail - y)
n = tail - y;
sc_vtb_delete(&scp->vtb, y*scp->xsize, n*scp->xsize, ch, attr);
mark_for_update(scp, y*scp->xsize);
mark_for_update(scp, scp->xsize*tail - 1);
}
static __inline void
sc_term_ins_char(scr_stat *scp, int n, int ch, int attr)
{
int count;
if (n < 1)
n = 1;
if (n > scp->xsize - scp->xpos)
n = scp->xsize - scp->xpos;
count = scp->xsize - (scp->xpos + n);
sc_vtb_move(&scp->vtb, scp->cursor_pos, scp->cursor_pos + n, count);
sc_vtb_erase(&scp->vtb, scp->cursor_pos, n, ch, attr);
mark_for_update(scp, scp->cursor_pos);
mark_for_update(scp, scp->cursor_pos + n + count - 1);
}
static __inline void
sc_term_del_char(scr_stat *scp, int n, int ch, int attr)
{
int count;
if (n < 1)
n = 1;
if (n > scp->xsize - scp->xpos)
n = scp->xsize - scp->xpos;
count = scp->xsize - (scp->xpos + n);
sc_vtb_move(&scp->vtb, scp->cursor_pos + n, scp->cursor_pos, count);
sc_vtb_erase(&scp->vtb, scp->cursor_pos + count, n, ch, attr);
mark_for_update(scp, scp->cursor_pos);
mark_for_update(scp, scp->cursor_pos + n + count - 1);
}
static __inline void
sc_term_col(scr_stat *scp, int n)
{
if (n < 1)
n = 1;
sc_move_cursor(scp, n - 1, scp->ypos);
}
static __inline void
sc_term_row(scr_stat *scp, int n)
{
if (n < 1)
n = 1;
sc_move_cursor(scp, scp->xpos, n - 1);
}
static __inline void
sc_term_up(scr_stat *scp, int n, int head)
{
if (n < 1)
n = 1;
n = imin(n, scp->ypos - head);
if (n <= 0)
return;
sc_move_cursor(scp, scp->xpos, scp->ypos - n);
}
static __inline void
sc_term_down(scr_stat *scp, int n, int tail)
{
if (tail <= 0)
tail = scp->ysize;
if (n < 1)
n = 1;
n = imin(n, tail - scp->ypos - 1);
if (n <= 0)
return;
sc_move_cursor(scp, scp->xpos, scp->ypos + n);
}
static __inline void
sc_term_left(scr_stat *scp, int n)
{
if (n < 1)
n = 1;
sc_move_cursor(scp, scp->xpos - n, scp->ypos);
}
static __inline void
sc_term_right(scr_stat *scp, int n)
{
if (n < 1)
n = 1;
sc_move_cursor(scp, scp->xpos + n, scp->ypos);
}
static __inline void
sc_term_up_scroll(scr_stat *scp, int n, int ch, int attr, int head, int tail)
{
if (tail <= 0)
tail = scp->ysize;
if (n < 1)
n = 1;
if (n <= scp->ypos - head) {
sc_move_cursor(scp, scp->xpos, scp->ypos - n);
} else {
sc_term_ins_line(scp, head, n - (scp->ypos - head),
ch, attr, tail);
sc_move_cursor(scp, scp->xpos, head);
}
}
static __inline void
sc_term_down_scroll(scr_stat *scp, int n, int ch, int attr, int head, int tail)
{
if (tail <= 0)
tail = scp->ysize;
if (n < 1)
n = 1;
if (n < tail - scp->ypos) {
sc_move_cursor(scp, scp->xpos, scp->ypos + n);
} else {
sc_term_del_line(scp, head, n - (tail - scp->ypos) + 1,
ch, attr, tail);
sc_move_cursor(scp, scp->xpos, tail - 1);
}
}
static __inline void
sc_term_clr_eos(scr_stat *scp, int n, int ch, int attr)
{
switch (n) {
case 0: /* clear form cursor to end of display */
sc_vtb_erase(&scp->vtb, scp->cursor_pos,
scp->xsize*scp->ysize - scp->cursor_pos,
ch, attr);
mark_for_update(scp, scp->cursor_pos);
mark_for_update(scp, scp->xsize*scp->ysize - 1);
sc_remove_cutmarking(scp);
break;
case 1: /* clear from beginning of display to cursor */
sc_vtb_erase(&scp->vtb, 0, scp->cursor_pos + 1, ch, attr);
mark_for_update(scp, 0);
mark_for_update(scp, scp->cursor_pos);
sc_remove_cutmarking(scp);
break;
case 2: /* clear entire display */
sc_vtb_erase(&scp->vtb, 0, scp->xsize*scp->ysize, ch, attr);
mark_for_update(scp, 0);
mark_for_update(scp, scp->xsize*scp->ysize - 1);
sc_remove_cutmarking(scp);
break;
}
}
static __inline void
sc_term_clr_eol(scr_stat *scp, int n, int ch, int attr)
{
switch (n) {
case 0: /* clear form cursor to end of line */
sc_vtb_erase(&scp->vtb, scp->cursor_pos,
scp->xsize - scp->xpos, ch, attr);
mark_for_update(scp, scp->cursor_pos);
mark_for_update(scp, scp->cursor_pos +
scp->xsize - 1 - scp->xpos);
break;
case 1: /* clear from beginning of line to cursor */
sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
scp->xpos + 1, ch, attr);
mark_for_update(scp, scp->ypos*scp->xsize);
mark_for_update(scp, scp->cursor_pos);
break;
case 2: /* clear entire line */
sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
scp->xsize, ch, attr);
mark_for_update(scp, scp->ypos*scp->xsize);
mark_for_update(scp, (scp->ypos + 1)*scp->xsize - 1);
break;
}
}
static __inline void
sc_term_tab(scr_stat *scp, int n)
{
int i;
if (n < 1)
n = 1;
i = (scp->xpos & ~7) + 8*n;
if (i >= scp->xsize) {
if (scp->ypos >= scp->ysize - 1) {
scp->xpos = 0;
scp->ypos++;
scp->cursor_pos = scp->ypos*scp->xsize;
} else
sc_move_cursor(scp, 0, scp->ypos + 1);
} else
sc_move_cursor(scp, i, scp->ypos);
}
static __inline void
sc_term_backtab(scr_stat *scp, int n)
{
int i;
if (n < 1)
n = 1;
if ((i = scp->xpos & ~7) == scp->xpos)
i -= 8*n;
else
i -= 8*(n - 1);
if (i < 0)
i = 0;
sc_move_cursor(scp, i, scp->ypos);
}
static __inline void
sc_term_respond(scr_stat *scp, u_char *s)
{
sc_paste(scp, s, strlen(s)); /* XXX: not correct, don't use rmap */
}
static __inline void
sc_term_gen_print(scr_stat *scp, u_char **buf, int *len, int attr)
{
vm_offset_t p;
u_char *ptr;
u_char *map;
int cnt;
int l;
int i;
ptr = *buf;
l = *len;
if (PRINTABLE(*ptr)) {
p = sc_vtb_pointer(&scp->vtb, scp->cursor_pos);
map = scp->sc->scr_map;
cnt = imin(l, scp->xsize - scp->xpos);
i = cnt;
do {
p = sc_vtb_putchar(&scp->vtb, p, map[*ptr], attr);
++ptr;
--i;
} while ((i > 0) && PRINTABLE(*ptr));
l -= cnt - i;
mark_for_update(scp, scp->cursor_pos);
scp->cursor_pos += cnt - i;
mark_for_update(scp, scp->cursor_pos - 1);
scp->xpos += cnt - i;
if (scp->xpos >= scp->xsize) {
scp->xpos = 0;
scp->ypos++;
/* we may have to scroll the screen */
}
} else {
switch(*ptr) {
case 0x07:
sc_bell(scp, scp->bell_pitch, scp->bell_duration);
break;
case 0x08: /* non-destructive backspace */
/* XXX */
if (scp->cursor_pos > 0) {
#if 0
mark_for_update(scp, scp->cursor_pos);
scp->cursor_pos--;
mark_for_update(scp, scp->cursor_pos);
#else
scp->cursor_pos--;
#endif
if (scp->xpos > 0) {
scp->xpos--;
} else {
scp->xpos += scp->xsize - 1;
scp->ypos--;
}
}
break;
case 0x09: /* non-destructive tab */
sc_term_tab(scp, 1);
/* we may have to scroll the screen */
#if 0
mark_for_update(scp, scp->cursor_pos);
scp->cursor_pos += (8 - scp->xpos % 8u);
mark_for_update(scp, scp->cursor_pos);
scp->xpos += (8 - scp->xpos % 8u);
if (scp->xpos >= scp->xsize) {
scp->xpos = 0;
scp->ypos++;
}
#endif
break;
case 0x0a: /* newline, same pos */
#if 0
mark_for_update(scp, scp->cursor_pos);
scp->cursor_pos += scp->xsize;
mark_for_update(scp, scp->cursor_pos);
#else
scp->cursor_pos += scp->xsize;
/* we may have to scroll the screen */
#endif
scp->ypos++;
break;
case 0x0c: /* form feed, clears screen */
sc_clear_screen(scp);
break;
case 0x0d: /* return, return to pos 0 */
#if 0
mark_for_update(scp, scp->cursor_pos);
scp->cursor_pos -= scp->xpos;
mark_for_update(scp, scp->cursor_pos);
#else
scp->cursor_pos -= scp->xpos;
#endif
scp->xpos = 0;
break;
}
ptr++; l--;
}
*buf = ptr;
*len = l;
}
static __inline void
sc_term_gen_scroll(scr_stat *scp, int ch, int attr)
{
/* do we have to scroll ?? */
if (scp->cursor_pos >= scp->ysize*scp->xsize) {
sc_remove_cutmarking(scp); /* XXX */
#ifndef SC_NO_HISTORY
if (scp->history != NULL)
sc_hist_save_one_line(scp, 0); /* XXX */
#endif
sc_vtb_delete(&scp->vtb, 0, scp->xsize, ch, attr);
scp->cursor_pos -= scp->xsize;
scp->ypos--;
mark_all(scp);
}
}
#endif /* _DEV_SYSCONS_SCTERMVAR_H_ */
|