19b934d09SEd Schouten /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni *
49b934d09SEd Schouten * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
59b934d09SEd Schouten * All rights reserved.
69b934d09SEd Schouten *
79b934d09SEd Schouten * Redistribution and use in source and binary forms, with or without
89b934d09SEd Schouten * modification, are permitted provided that the following conditions
99b934d09SEd Schouten * are met:
109b934d09SEd Schouten * 1. Redistributions of source code must retain the above copyright
119b934d09SEd Schouten * notice, this list of conditions and the following disclaimer.
129b934d09SEd Schouten * 2. Redistributions in binary form must reproduce the above copyright
139b934d09SEd Schouten * notice, this list of conditions and the following disclaimer in the
149b934d09SEd Schouten * documentation and/or other materials provided with the distribution.
159b934d09SEd Schouten *
169b934d09SEd Schouten * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
179b934d09SEd Schouten * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189b934d09SEd Schouten * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199b934d09SEd Schouten * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
209b934d09SEd Schouten * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219b934d09SEd Schouten * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229b934d09SEd Schouten * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239b934d09SEd Schouten * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249b934d09SEd Schouten * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259b934d09SEd Schouten * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269b934d09SEd Schouten * SUCH DAMAGE.
279b934d09SEd Schouten */
289b934d09SEd Schouten
299b934d09SEd Schouten static void
teken_subr_cons25_set_border(const teken_t * t,unsigned int c)3092223bddSPoul-Henning Kamp teken_subr_cons25_set_border(const teken_t *t, unsigned int c)
31dd833891SBruce Evans {
32dd833891SBruce Evans
33dd833891SBruce Evans teken_funcs_param(t, TP_SETBORDER, c);
34dd833891SBruce Evans }
35dd833891SBruce Evans
36dd833891SBruce Evans static void
teken_subr_cons25_set_global_cursor_shape(const teken_t * t,unsigned int ncmds,const unsigned int cmds[])3792223bddSPoul-Henning Kamp teken_subr_cons25_set_global_cursor_shape(const teken_t *t, unsigned int ncmds,
3892223bddSPoul-Henning Kamp const unsigned int cmds[])
3915e0c651SBruce Evans {
4015e0c651SBruce Evans unsigned int code, i;
4115e0c651SBruce Evans
4215e0c651SBruce Evans /*
4315e0c651SBruce Evans * Pack the args to work around API deficiencies. This requires
4415e0c651SBruce Evans * knowing too much about the low level to be fully compatible.
4515e0c651SBruce Evans * Returning when ncmds > 3 is necessary and happens to be
4615e0c651SBruce Evans * compatible. Discarding high bits is necessary and happens to
4715e0c651SBruce Evans * be incompatible only for invalid args when ncmds == 3.
4815e0c651SBruce Evans */
4915e0c651SBruce Evans if (ncmds > 3)
5015e0c651SBruce Evans return;
5115e0c651SBruce Evans code = 0;
5215e0c651SBruce Evans for (i = ncmds; i > 0; i--)
5315e0c651SBruce Evans code = (code << 8) | (cmds[i - 1] & 0xff);
5415e0c651SBruce Evans code = (code << 8) | ncmds;
5515e0c651SBruce Evans teken_funcs_param(t, TP_SETGLOBALCURSOR, code);
5615e0c651SBruce Evans }
5715e0c651SBruce Evans
5815e0c651SBruce Evans static void
teken_subr_cons25_set_local_cursor_type(const teken_t * t,unsigned int type)5992223bddSPoul-Henning Kamp teken_subr_cons25_set_local_cursor_type(const teken_t *t, unsigned int type)
609b934d09SEd Schouten {
619b934d09SEd Schouten
6215e0c651SBruce Evans teken_funcs_param(t, TP_SETLOCALCURSOR, type);
639b934d09SEd Schouten }
649b934d09SEd Schouten
659b934d09SEd Schouten static const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
66cf8880d5SEd Maste TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_YELLOW, TC_WHITE };
679b934d09SEd Schouten
689b934d09SEd Schouten static void
teken_subr_cons25_set_default_background(teken_t * t,unsigned int c)6997933a41SBruce Evans teken_subr_cons25_set_default_background(teken_t *t, unsigned int c)
709b934d09SEd Schouten {
719b934d09SEd Schouten
724eb235fbSBruce Evans t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
734eb235fbSBruce Evans t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
749b934d09SEd Schouten }
759b934d09SEd Schouten
769b934d09SEd Schouten static void
teken_subr_cons25_set_default_foreground(teken_t * t,unsigned int c)7797933a41SBruce Evans teken_subr_cons25_set_default_foreground(teken_t *t, unsigned int c)
789b934d09SEd Schouten {
799b934d09SEd Schouten
804eb235fbSBruce Evans t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
814eb235fbSBruce Evans t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
829b934d09SEd Schouten }
839b934d09SEd Schouten
84eba77f5cSEd Schouten static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
85eba77f5cSEd Schouten
86eba77f5cSEd Schouten void
teken_get_defattr_cons25(const teken_t * t,int * fg,int * bg)8792223bddSPoul-Henning Kamp teken_get_defattr_cons25(const teken_t *t, int *fg, int *bg)
88eba77f5cSEd Schouten {
89eba77f5cSEd Schouten
9056a4365bSEd Schouten *fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
91eba77f5cSEd Schouten if (t->t_defattr.ta_format & TF_BOLD)
92eba77f5cSEd Schouten *fg += 8;
9356a4365bSEd Schouten *bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
94eba77f5cSEd Schouten }
95eba77f5cSEd Schouten
969b934d09SEd Schouten static void
teken_subr_cons25_switch_virtual_terminal(const teken_t * t,unsigned int vt)9792223bddSPoul-Henning Kamp teken_subr_cons25_switch_virtual_terminal(const teken_t *t, unsigned int vt)
989b934d09SEd Schouten {
999b934d09SEd Schouten
1009b934d09SEd Schouten teken_funcs_param(t, TP_SWITCHVT, vt);
1019b934d09SEd Schouten }
1029b934d09SEd Schouten
1039b934d09SEd Schouten static void
teken_subr_cons25_set_bell_pitch_duration(const teken_t * t,unsigned int pitch,unsigned int duration)10492223bddSPoul-Henning Kamp teken_subr_cons25_set_bell_pitch_duration(const teken_t *t, unsigned int pitch,
1059b934d09SEd Schouten unsigned int duration)
1069b934d09SEd Schouten {
1079b934d09SEd Schouten
1089b934d09SEd Schouten teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
1099b934d09SEd Schouten (duration & 0xffff));
1109b934d09SEd Schouten }
1119b934d09SEd Schouten
1122c549cc4SEd Schouten static void
teken_subr_cons25_set_graphic_rendition(teken_t * t,unsigned int cmd,unsigned int param)11368fdfe29SEd Schouten teken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
11492223bddSPoul-Henning Kamp unsigned int param)
11568fdfe29SEd Schouten {
11668fdfe29SEd Schouten
11792223bddSPoul-Henning Kamp (void)param;
11868fdfe29SEd Schouten switch (cmd) {
11968fdfe29SEd Schouten case 0: /* Reset. */
12068fdfe29SEd Schouten t->t_curattr = t->t_defattr;
12168fdfe29SEd Schouten break;
12268fdfe29SEd Schouten default:
12368fdfe29SEd Schouten teken_printf("unsupported attribute %u\n", cmd);
12468fdfe29SEd Schouten }
12568fdfe29SEd Schouten }
12668fdfe29SEd Schouten
12768fdfe29SEd Schouten static void
teken_subr_cons25_set_terminal_mode(teken_t * t,unsigned int mode)1282c549cc4SEd Schouten teken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
1292c549cc4SEd Schouten {
1302c549cc4SEd Schouten
1312c549cc4SEd Schouten switch (mode) {
1322c549cc4SEd Schouten case 0: /* Switch terminal to xterm. */
1332c549cc4SEd Schouten t->t_stateflags &= ~TS_CONS25;
1342c549cc4SEd Schouten break;
1352c549cc4SEd Schouten case 1: /* Switch terminal to cons25. */
1362c549cc4SEd Schouten t->t_stateflags |= TS_CONS25;
1372c549cc4SEd Schouten break;
13892223bddSPoul-Henning Kamp default:
13992223bddSPoul-Henning Kamp break;
1402c549cc4SEd Schouten }
1412c549cc4SEd Schouten }
1422c549cc4SEd Schouten
1439b934d09SEd Schouten #if 0
1449b934d09SEd Schouten static void
1459b934d09SEd Schouten teken_subr_vt52_decid(teken_t *t)
1469b934d09SEd Schouten {
1479b934d09SEd Schouten const char response[] = "\x1B/Z";
1489b934d09SEd Schouten
1499b934d09SEd Schouten teken_funcs_respond(t, response, sizeof response - 1);
1509b934d09SEd Schouten }
1519b934d09SEd Schouten #endif
152