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.
29 #ifndef _DEV_SYSCONS_SCTERMVAR_H_
30 #define _DEV_SYSCONS_SCTERMVAR_H_
33 * building blocks for terminal emulator modules.
36 static __inline void sc_term_ins_line(scr_stat *scp, int y, int n, int ch,
38 static __inline void sc_term_del_line(scr_stat *scp, int y, int n, int ch,
40 static __inline void sc_term_ins_char(scr_stat *scp, int n, int ch,
42 static __inline void sc_term_del_char(scr_stat *scp, int n, int ch,
44 static __inline void sc_term_col(scr_stat *scp, int n);
45 static __inline void sc_term_row(scr_stat *scp, int n);
46 static __inline void sc_term_up(scr_stat *scp, int n, int head);
47 static __inline void sc_term_down(scr_stat *scp, int n, int tail);
48 static __inline void sc_term_left(scr_stat *scp, int n);
49 static __inline void sc_term_right(scr_stat *scp, int n);
50 static __inline void sc_term_up_scroll(scr_stat *scp, int n, int ch,
51 int attr, int head, int tail);
52 static __inline void sc_term_down_scroll(scr_stat *scp, int n, int ch,
53 int attr, int head, int tail);
54 static __inline void sc_term_clr_eos(scr_stat *scp, int n, int ch, int attr);
55 static __inline void sc_term_clr_eol(scr_stat *scp, int n, int ch, int attr);
56 static __inline void sc_term_tab(scr_stat *scp, int n);
57 static __inline void sc_term_backtab(scr_stat *scp, int n);
58 static __inline void sc_term_respond(scr_stat *scp, u_char *s);
59 static __inline void sc_term_gen_print(scr_stat *scp, u_char **buf, int *len,
61 static __inline void sc_term_gen_scroll(scr_stat *scp, int ch, int attr);
64 sc_term_ins_line(scr_stat *scp, int y, int n, int ch, int attr, int tail)
72 sc_vtb_ins(&scp->vtb, y*scp->xsize, n*scp->xsize, ch, attr);
73 mark_for_update(scp, y*scp->xsize);
74 mark_for_update(scp, scp->xsize*tail - 1);
78 sc_term_del_line(scr_stat *scp, int y, int n, int ch, int attr, int tail)
86 sc_vtb_delete(&scp->vtb, y*scp->xsize, n*scp->xsize, ch, attr);
87 mark_for_update(scp, y*scp->xsize);
88 mark_for_update(scp, scp->xsize*tail - 1);
92 sc_term_ins_char(scr_stat *scp, int n, int ch, int attr)
98 if (n > scp->xsize - scp->xpos)
99 n = scp->xsize - scp->xpos;
100 count = scp->xsize - (scp->xpos + n);
101 sc_vtb_move(&scp->vtb, scp->cursor_pos, scp->cursor_pos + n, count);
102 sc_vtb_erase(&scp->vtb, scp->cursor_pos, n, ch, attr);
103 mark_for_update(scp, scp->cursor_pos);
104 mark_for_update(scp, scp->cursor_pos + n + count - 1);
108 sc_term_del_char(scr_stat *scp, int n, int ch, int attr)
114 if (n > scp->xsize - scp->xpos)
115 n = scp->xsize - scp->xpos;
116 count = scp->xsize - (scp->xpos + n);
117 sc_vtb_move(&scp->vtb, scp->cursor_pos + n, scp->cursor_pos, count);
118 sc_vtb_erase(&scp->vtb, scp->cursor_pos + count, n, ch, attr);
119 mark_for_update(scp, scp->cursor_pos);
120 mark_for_update(scp, scp->cursor_pos + n + count - 1);
124 sc_term_col(scr_stat *scp, int n)
128 sc_move_cursor(scp, n - 1, scp->ypos);
132 sc_term_row(scr_stat *scp, int n)
136 sc_move_cursor(scp, scp->xpos, n - 1);
140 sc_term_up(scr_stat *scp, int n, int head)
144 n = imin(n, scp->ypos - head);
147 sc_move_cursor(scp, scp->xpos, scp->ypos - n);
151 sc_term_down(scr_stat *scp, int n, int tail)
157 n = imin(n, tail - scp->ypos - 1);
160 sc_move_cursor(scp, scp->xpos, scp->ypos + n);
164 sc_term_left(scr_stat *scp, int n)
168 sc_move_cursor(scp, scp->xpos - n, scp->ypos);
172 sc_term_right(scr_stat *scp, int n)
176 sc_move_cursor(scp, scp->xpos + n, scp->ypos);
180 sc_term_up_scroll(scr_stat *scp, int n, int ch, int attr, int head, int tail)
186 if (n <= scp->ypos - head) {
187 sc_move_cursor(scp, scp->xpos, scp->ypos - n);
189 sc_term_ins_line(scp, head, n - (scp->ypos - head),
191 sc_move_cursor(scp, scp->xpos, head);
196 sc_term_down_scroll(scr_stat *scp, int n, int ch, int attr, int head, int tail)
202 if (n < tail - scp->ypos) {
203 sc_move_cursor(scp, scp->xpos, scp->ypos + n);
205 sc_term_del_line(scp, head, n - (tail - scp->ypos) + 1,
207 sc_move_cursor(scp, scp->xpos, tail - 1);
212 sc_term_clr_eos(scr_stat *scp, int n, int ch, int attr)
215 case 0: /* clear form cursor to end of display */
216 sc_vtb_erase(&scp->vtb, scp->cursor_pos,
217 scp->xsize*scp->ysize - scp->cursor_pos,
219 mark_for_update(scp, scp->cursor_pos);
220 mark_for_update(scp, scp->xsize*scp->ysize - 1);
221 sc_remove_cutmarking(scp);
223 case 1: /* clear from beginning of display to cursor */
224 sc_vtb_erase(&scp->vtb, 0, scp->cursor_pos + 1, ch, attr);
225 mark_for_update(scp, 0);
226 mark_for_update(scp, scp->cursor_pos);
227 sc_remove_cutmarking(scp);
229 case 2: /* clear entire display */
230 sc_vtb_erase(&scp->vtb, 0, scp->xsize*scp->ysize, ch, attr);
231 mark_for_update(scp, 0);
232 mark_for_update(scp, scp->xsize*scp->ysize - 1);
233 sc_remove_cutmarking(scp);
239 sc_term_clr_eol(scr_stat *scp, int n, int ch, int attr)
242 case 0: /* clear form cursor to end of line */
243 sc_vtb_erase(&scp->vtb, scp->cursor_pos,
244 scp->xsize - scp->xpos, ch, attr);
245 mark_for_update(scp, scp->cursor_pos);
246 mark_for_update(scp, scp->cursor_pos +
247 scp->xsize - 1 - scp->xpos);
249 case 1: /* clear from beginning of line to cursor */
250 sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
251 scp->xpos + 1, ch, attr);
252 mark_for_update(scp, scp->ypos*scp->xsize);
253 mark_for_update(scp, scp->cursor_pos);
255 case 2: /* clear entire line */
256 sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
257 scp->xsize, ch, attr);
258 mark_for_update(scp, scp->ypos*scp->xsize);
259 mark_for_update(scp, (scp->ypos + 1)*scp->xsize - 1);
265 sc_term_tab(scr_stat *scp, int n)
271 i = (scp->xpos & ~7) + 8*n;
272 if (i >= scp->xsize) {
273 if (scp->ypos >= scp->ysize - 1) {
276 scp->cursor_pos = scp->ypos*scp->xsize;
278 sc_move_cursor(scp, 0, scp->ypos + 1);
280 sc_move_cursor(scp, i, scp->ypos);
284 sc_term_backtab(scr_stat *scp, int n)
290 if ((i = scp->xpos & ~7) == scp->xpos)
296 sc_move_cursor(scp, i, scp->ypos);
300 sc_term_respond(scr_stat *scp, u_char *s)
302 sc_paste(scp, s, strlen(s)); /* XXX: not correct, don't use rmap */
306 sc_term_gen_print(scr_stat *scp, u_char **buf, int *len, int attr)
318 if (PRINTABLE(*ptr)) {
319 p = sc_vtb_pointer(&scp->vtb, scp->cursor_pos);
320 map = scp->sc->scr_map;
322 cnt = imin(l, scp->xsize - scp->xpos);
325 p = sc_vtb_putchar(&scp->vtb, p, map[*ptr], attr);
328 } while ((i > 0) && PRINTABLE(*ptr));
331 mark_for_update(scp, scp->cursor_pos);
332 scp->cursor_pos += cnt - i;
333 mark_for_update(scp, scp->cursor_pos - 1);
334 scp->xpos += cnt - i;
336 if (scp->xpos >= scp->xsize) {
339 /* we may have to scroll the screen */
344 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
347 case 0x08: /* non-destructive backspace */
349 if (scp->cursor_pos > 0) {
351 mark_for_update(scp, scp->cursor_pos);
353 mark_for_update(scp, scp->cursor_pos);
360 scp->xpos += scp->xsize - 1;
366 case 0x09: /* non-destructive tab */
368 /* we may have to scroll the screen */
370 mark_for_update(scp, scp->cursor_pos);
371 scp->cursor_pos += (8 - scp->xpos % 8u);
372 mark_for_update(scp, scp->cursor_pos);
373 scp->xpos += (8 - scp->xpos % 8u);
374 if (scp->xpos >= scp->xsize) {
381 case 0x0a: /* newline, same pos */
383 mark_for_update(scp, scp->cursor_pos);
384 scp->cursor_pos += scp->xsize;
385 mark_for_update(scp, scp->cursor_pos);
387 scp->cursor_pos += scp->xsize;
388 /* we may have to scroll the screen */
393 case 0x0c: /* form feed, clears screen */
394 sc_clear_screen(scp);
397 case 0x0d: /* return, return to pos 0 */
399 mark_for_update(scp, scp->cursor_pos);
400 scp->cursor_pos -= scp->xpos;
401 mark_for_update(scp, scp->cursor_pos);
403 scp->cursor_pos -= scp->xpos;
416 sc_term_gen_scroll(scr_stat *scp, int ch, int attr)
418 /* do we have to scroll ?? */
419 if (scp->cursor_pos >= scp->ysize*scp->xsize) {
420 sc_remove_cutmarking(scp); /* XXX */
421 #ifndef SC_NO_HISTORY
422 if (scp->history != NULL)
423 sc_hist_save_one_line(scp, 0); /* XXX */
425 sc_vtb_delete(&scp->vtb, 0, scp->xsize, ch, attr);
426 scp->cursor_pos -= scp->xsize;
432 #endif /* _DEV_SYSCONS_SCTERMVAR_H_ */