1186681Sed/*-
2186681Sed * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
3186681Sed * All rights reserved.
4186681Sed *
5186681Sed * Redistribution and use in source and binary forms, with or without
6186681Sed * modification, are permitted provided that the following conditions
7186681Sed * are met:
8186681Sed * 1. Redistributions of source code must retain the above copyright
9186681Sed *    notice, this list of conditions and the following disclaimer.
10186681Sed * 2. Redistributions in binary form must reproduce the above copyright
11186681Sed *    notice, this list of conditions and the following disclaimer in the
12186681Sed *    documentation and/or other materials provided with the distribution.
13186681Sed *
14186681Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15186681Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16186681Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17186681Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18186681Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19186681Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20186681Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21186681Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22186681Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23186681Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24186681Sed * SUCH DAMAGE.
25186681Sed *
26186681Sed * $FreeBSD$
27186681Sed */
28186681Sed
29186681Sedstatic void
30186681Sedteken_subr_cons25_set_cursor_type(teken_t *t, unsigned int type)
31186681Sed{
32186681Sed
33186681Sed	teken_funcs_param(t, TP_SHOWCURSOR, type != 1);
34186681Sed}
35186681Sed
36187382Sedstatic const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
37187382Sed    TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_BROWN, TC_WHITE };
38187374Sed
39186681Sedstatic void
40187373Sedteken_subr_cons25_set_adapter_background(teken_t *t, unsigned int c)
41187373Sed{
42187373Sed
43187374Sed	t->t_defattr.ta_bgcolor = cons25_colors[c % 8];
44187374Sed	t->t_curattr.ta_bgcolor = cons25_colors[c % 8];
45187373Sed}
46187373Sed
47187373Sedstatic void
48187373Sedteken_subr_cons25_set_adapter_foreground(teken_t *t, unsigned int c)
49187373Sed{
50187373Sed
51187374Sed	t->t_defattr.ta_fgcolor = cons25_colors[c % 8];
52187374Sed	t->t_curattr.ta_fgcolor = cons25_colors[c % 8];
53187373Sed	if (c >= 8) {
54187373Sed		t->t_defattr.ta_format |= TF_BOLD;
55187373Sed		t->t_curattr.ta_format |= TF_BOLD;
56187373Sed	} else {
57187373Sed		t->t_defattr.ta_format &= ~TF_BOLD;
58187373Sed		t->t_curattr.ta_format &= ~TF_BOLD;
59187373Sed	}
60187373Sed}
61187373Sed
62197117Sedstatic const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
63197117Sed
64197117Sedvoid
65197117Sedteken_get_defattr_cons25(teken_t *t, int *fg, int *bg)
66197117Sed{
67197117Sed
68197522Sed	*fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
69197117Sed	if (t->t_defattr.ta_format & TF_BOLD)
70197117Sed		*fg += 8;
71197522Sed	*bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
72197117Sed}
73197117Sed
74187373Sedstatic void
75186681Sedteken_subr_cons25_switch_virtual_terminal(teken_t *t, unsigned int vt)
76186681Sed{
77186681Sed
78186681Sed	teken_funcs_param(t, TP_SWITCHVT, vt);
79186681Sed}
80186681Sed
81193184Sedstatic void
82193184Sedteken_subr_cons25_set_bell_pitch_duration(teken_t *t, unsigned int pitch,
83193184Sed    unsigned int duration)
84193184Sed{
85193184Sed
86193184Sed	teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
87193184Sed	    (duration & 0xffff));
88193184Sed}
89193184Sed
90197481Sedstatic void
91214817Sedteken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
92214817Sed    unsigned int param __unused)
93214817Sed{
94214817Sed
95214817Sed	switch (cmd) {
96214817Sed	case 0: /* Reset. */
97214817Sed		t->t_curattr = t->t_defattr;
98214817Sed		break;
99214817Sed	default:
100214817Sed		teken_printf("unsupported attribute %u\n", cmd);
101214817Sed	}
102214817Sed}
103214817Sed
104214817Sedstatic void
105197481Sedteken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
106197481Sed{
107197481Sed
108197481Sed	switch (mode) {
109197481Sed	case 0:	/* Switch terminal to xterm. */
110197481Sed		t->t_stateflags &= ~TS_CONS25;
111197481Sed		break;
112197481Sed	case 1: /* Switch terminal to cons25. */
113197481Sed		t->t_stateflags |= TS_CONS25;
114197481Sed		break;
115197481Sed	}
116197481Sed}
117197481Sed
118186681Sed#if 0
119186681Sedstatic void
120186681Sedteken_subr_vt52_decid(teken_t *t)
121186681Sed{
122186681Sed	const char response[] = "\x1B/Z";
123186681Sed
124186681Sed	teken_funcs_respond(t, response, sizeof response - 1);
125186681Sed}
126186681Sed#endif
127