2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/syscons/sctermvar.h,v 1.1.2.2 2001/07/28 12:51:47 yokota Exp $
27 * $DragonFly: src/sys/dev/misc/syscons/sctermvar.h,v 1.4 2005/05/27 20:57:40 swildner Exp $
30 #ifndef _DEV_SYSCONS_SCTERMVAR_H_
31 #define _DEV_SYSCONS_SCTERMVAR_H_
34 * building blocks for terminal emulator modules.
37 static __inline void sc_term_ins_line(scr_stat *scp, int y, int n, int ch,
39 static __inline void sc_term_del_line(scr_stat *scp, int y, int n, int ch,
41 static __inline void sc_term_ins_char(scr_stat *scp, int n, int ch,
43 static __inline void sc_term_del_char(scr_stat *scp, int n, int ch,
45 static __inline void sc_term_col(scr_stat *scp, int n);
46 static __inline void sc_term_row(scr_stat *scp, int n);
47 static __inline void sc_term_up(scr_stat *scp, int n, int head);
48 static __inline void sc_term_down(scr_stat *scp, int n, int tail);
49 static __inline void sc_term_left(scr_stat *scp, int n);
50 static __inline void sc_term_right(scr_stat *scp, int n);
51 static __inline void sc_term_up_scroll(scr_stat *scp, int n, int ch,
52 int attr, int head, int tail);
53 static __inline void sc_term_down_scroll(scr_stat *scp, int n, int ch,
54 int attr, int head, int tail);
55 static __inline void sc_term_clr_eos(scr_stat *scp, int n, int ch, int attr);
56 static __inline void sc_term_clr_eol(scr_stat *scp, int n, int ch, int attr);
57 static __inline void sc_term_tab(scr_stat *scp, int n);
58 static __inline void sc_term_backtab(scr_stat *scp, int n);
59 static __inline void sc_term_respond(scr_stat *scp, u_char *s);
60 static __inline void sc_term_gen_print(scr_stat *scp, u_char **buf, int *len,
62 static __inline void sc_term_gen_scroll(scr_stat *scp, int ch, int attr);
65 sc_term_ins_line(scr_stat *scp, int y, int n, int ch, int attr, int tail)
73 sc_vtb_ins(&scp->vtb, y*scp->xsize, n*scp->xsize, ch, attr);
74 mark_for_update(scp, y*scp->xsize);
75 mark_for_update(scp, scp->xsize*tail - 1);
79 sc_term_del_line(scr_stat *scp, int y, int n, int ch, int attr, int tail)
87 sc_vtb_delete(&scp->vtb, y*scp->xsize, n*scp->xsize, ch, attr);
88 mark_for_update(scp, y*scp->xsize);
89 mark_for_update(scp, scp->xsize*tail - 1);
93 sc_term_ins_char(scr_stat *scp, int n, int ch, int attr)
99 if (n > scp->xsize - scp->xpos)
100 n = scp->xsize - scp->xpos;
101 count = scp->xsize - (scp->xpos + n);
102 sc_vtb_move(&scp->vtb, scp->cursor_pos, scp->cursor_pos + n, count);
103 sc_vtb_erase(&scp->vtb, scp->cursor_pos, n, ch, attr);
104 mark_for_update(scp, scp->cursor_pos);
105 mark_for_update(scp, scp->cursor_pos + n + count - 1);
109 sc_term_del_char(scr_stat *scp, int n, int ch, int attr)
115 if (n > scp->xsize - scp->xpos)
116 n = scp->xsize - scp->xpos;
117 count = scp->xsize - (scp->xpos + n);
118 sc_vtb_move(&scp->vtb, scp->cursor_pos + n, scp->cursor_pos, count);
119 sc_vtb_erase(&scp->vtb, scp->cursor_pos + count, n, ch, attr);
120 mark_for_update(scp, scp->cursor_pos);
121 mark_for_update(scp, scp->cursor_pos + n + count - 1);
125 sc_term_col(scr_stat *scp, int n)
129 sc_move_cursor(scp, n - 1, scp->ypos);
133 sc_term_row(scr_stat *scp, int n)
137 sc_move_cursor(scp, scp->xpos, n - 1);
141 sc_term_up(scr_stat *scp, int n, int head)
145 n = imin(n, scp->ypos - head);
148 sc_move_cursor(scp, scp->xpos, scp->ypos - n);
152 sc_term_down(scr_stat *scp, int n, int tail)
158 n = imin(n, tail - scp->ypos - 1);
161 sc_move_cursor(scp, scp->xpos, scp->ypos + n);
165 sc_term_left(scr_stat *scp, int n)
169 sc_move_cursor(scp, scp->xpos - n, scp->ypos);
173 sc_term_right(scr_stat *scp, int n)
177 sc_move_cursor(scp, scp->xpos + n, scp->ypos);
181 sc_term_up_scroll(scr_stat *scp, int n, int ch, int attr, int head, int tail)
187 if (n <= scp->ypos - head) {
188 sc_move_cursor(scp, scp->xpos, scp->ypos - n);
190 sc_term_ins_line(scp, head, n - (scp->ypos - head),
192 sc_move_cursor(scp, scp->xpos, head);
197 sc_term_down_scroll(scr_stat *scp, int n, int ch, int attr, int head, int tail)
203 if (n < tail - scp->ypos) {
204 sc_move_cursor(scp, scp->xpos, scp->ypos + n);
206 sc_term_del_line(scp, head, n - (tail - scp->ypos) + 1,
208 sc_move_cursor(scp, scp->xpos, tail - 1);
213 sc_term_clr_eos(scr_stat *scp, int n, int ch, int attr)
216 case 0: /* clear form cursor to end of display */
217 sc_vtb_erase(&scp->vtb, scp->cursor_pos,
218 scp->xsize*scp->ysize - scp->cursor_pos,
220 mark_for_update(scp, scp->cursor_pos);
221 mark_for_update(scp, scp->xsize*scp->ysize - 1);
222 sc_remove_cutmarking(scp);
224 case 1: /* clear from beginning of display to cursor */
225 sc_vtb_erase(&scp->vtb, 0, scp->cursor_pos + 1, ch, attr);
226 mark_for_update(scp, 0);
227 mark_for_update(scp, scp->cursor_pos);
228 sc_remove_cutmarking(scp);
230 case 2: /* clear entire display */
231 sc_vtb_erase(&scp->vtb, 0, scp->xsize*scp->ysize, ch, attr);
232 mark_for_update(scp, 0);
233 mark_for_update(scp, scp->xsize*scp->ysize - 1);
234 sc_remove_cutmarking(scp);
240 sc_term_clr_eol(scr_stat *scp, int n, int ch, int attr)
243 case 0: /* clear form cursor to end of line */
244 sc_vtb_erase(&scp->vtb, scp->cursor_pos,
245 scp->xsize - scp->xpos, ch, attr);
246 mark_for_update(scp, scp->cursor_pos);
247 mark_for_update(scp, scp->cursor_pos +
248 scp->xsize - 1 - scp->xpos);
250 case 1: /* clear from beginning of line to cursor */
251 sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
252 scp->xpos + 1, ch, attr);
253 mark_for_update(scp, scp->ypos*scp->xsize);
254 mark_for_update(scp, scp->cursor_pos);
256 case 2: /* clear entire line */
257 sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
258 scp->xsize, ch, attr);
259 mark_for_update(scp, scp->ypos*scp->xsize);
260 mark_for_update(scp, (scp->ypos + 1)*scp->xsize - 1);
266 sc_term_tab(scr_stat *scp, int n)
272 i = (scp->xpos & ~7) + 8*n;
273 if (i >= scp->xsize) {
274 if (scp->ypos >= scp->ysize - 1) {
277 scp->cursor_pos = scp->ypos*scp->xsize;
279 sc_move_cursor(scp, 0, scp->ypos + 1);
281 sc_move_cursor(scp, i, scp->ypos);
285 sc_term_backtab(scr_stat *scp, int n)
291 if ((i = scp->xpos & ~7) == scp->xpos)
297 sc_move_cursor(scp, i, scp->ypos);
301 sc_term_respond(scr_stat *scp, u_char *s)
303 sc_paste(scp, s, strlen(s)); /* XXX: not correct, don't use rmap */
307 sc_term_gen_print(scr_stat *scp, u_char **buf, int *len, int attr)
319 if (PRINTABLE(*ptr)) {
320 p = scp->vtb.vtb_buffer + scp->cursor_pos;
321 map = scp->sc->scr_map;
323 cnt = imin(l, scp->xsize - scp->xpos);
326 p = sc_vtb_putchar(&scp->vtb, p, map[*ptr], attr);
329 } while ((i > 0) && PRINTABLE(*ptr));
332 mark_for_update(scp, scp->cursor_pos);
333 scp->cursor_pos += cnt - i;
334 mark_for_update(scp, scp->cursor_pos - 1);
335 scp->xpos += cnt - i;
337 if (scp->xpos >= scp->xsize) {
340 /* we may have to scroll the screen */
345 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
348 case 0x08: /* non-destructive backspace */
350 if (scp->cursor_pos > 0) {
352 mark_for_update(scp, scp->cursor_pos);
354 mark_for_update(scp, scp->cursor_pos);
361 scp->xpos += scp->xsize - 1;
367 case 0x09: /* non-destructive tab */
369 /* we may have to scroll the screen */
371 mark_for_update(scp, scp->cursor_pos);
372 scp->cursor_pos += (8 - scp->xpos % 8u);
373 mark_for_update(scp, scp->cursor_pos);
374 scp->xpos += (8 - scp->xpos % 8u);
375 if (scp->xpos >= scp->xsize) {
382 case 0x0a: /* newline, same pos */
384 mark_for_update(scp, scp->cursor_pos);
385 scp->cursor_pos += scp->xsize;
386 mark_for_update(scp, scp->cursor_pos);
388 scp->cursor_pos += scp->xsize;
389 /* we may have to scroll the screen */
394 case 0x0c: /* form feed, clears screen */
395 sc_clear_screen(scp);
398 case 0x0d: /* return, return to pos 0 */
400 mark_for_update(scp, scp->cursor_pos);
401 scp->cursor_pos -= scp->xpos;
402 mark_for_update(scp, scp->cursor_pos);
404 scp->cursor_pos -= scp->xpos;
417 sc_term_gen_scroll(scr_stat *scp, int ch, int attr)
419 /* do we have to scroll ?? */
420 if (scp->cursor_pos >= scp->ysize*scp->xsize) {
421 sc_remove_cutmarking(scp); /* XXX */
422 #ifndef SC_NO_HISTORY
423 if (scp->history != NULL)
424 sc_hist_save_one_line(scp, 0); /* XXX */
426 sc_vtb_delete(&scp->vtb, 0, scp->xsize, ch, attr);
427 scp->cursor_pos -= scp->xsize;
433 #endif /* _DEV_SYSCONS_SCTERMVAR_H_ */