Module Name:    src
Committed By:   tsutsui
Date:           Sat Jun 25 03:18:38 UTC 2022

Modified Files:
        src/sys/arch/x68k/dev: ite.c ite_tv.c itevar.h

Log Message:
Add a minimum box drawing character support for x68k ite(4).

This is for proper appearance of menus in sysinst(8) with TERM=vt220.
Discussed on port-x68k@ etc.

There was "why not all G0/G1/G2/G3" comment, but terminfo and curses
with TERM=vt220 only require "ESC ( <F>" against G0 for DEC special
graphics (including box drawing characters) by smacs/rmacs/acsc.
I hope other various unimplemented ISO/IEC 2022 specifications will
be motivated per further visible demends.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/x68k/dev/ite.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x68k/dev/ite_tv.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/dev/itevar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x68k/dev/ite.c
diff -u src/sys/arch/x68k/dev/ite.c:1.68 src/sys/arch/x68k/dev/ite.c:1.69
--- src/sys/arch/x68k/dev/ite.c:1.68	Sat May 28 10:36:22 2022
+++ src/sys/arch/x68k/dev/ite.c	Sat Jun 25 03:18:38 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ite.c,v 1.68 2022/05/28 10:36:22 andvar Exp $	*/
+/*	$NetBSD: ite.c,v 1.69 2022/06/25 03:18:38 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.68 2022/05/28 10:36:22 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.69 2022/06/25 03:18:38 tsutsui Exp $");
 
 #include "ite.h"
 #if NITE > 0
@@ -94,33 +94,33 @@ void opm_bell(void);
 
 struct consdev;
 
-inline static void itesendch(int);
-inline static void alignment_display(struct ite_softc *);
-inline static void snap_cury(struct ite_softc *);
-inline static void ite_dnchar(struct ite_softc *, int);
+static inline void itesendch(int);
+static inline void alignment_display(struct ite_softc *);
+static inline void snap_cury(struct ite_softc *);
+static inline void ite_dnchar(struct ite_softc *, int);
 static void ite_inchar(struct ite_softc *,	int);
-inline static void ite_clrtoeol(struct ite_softc *);
-inline static void ite_clrtobol(struct ite_softc *);
-inline static void ite_clrline(struct ite_softc *);
-inline static void ite_clrtoeos(struct ite_softc *);
-inline static void ite_clrtobos(struct ite_softc *);
-inline static void ite_clrscreen(struct ite_softc *);
-inline static void ite_dnline(struct ite_softc *, int);
-inline static void ite_inline(struct ite_softc *, int);
-inline static void ite_index(struct ite_softc *);
-inline static void ite_lf(struct ite_softc *);
-inline static void ite_crlf(struct ite_softc *);
-inline static void ite_cr(struct ite_softc *);
-inline static void ite_rlf(struct ite_softc *);
+static inline void ite_clrtoeol(struct ite_softc *);
+static inline void ite_clrtobol(struct ite_softc *);
+static inline void ite_clrline(struct ite_softc *);
+static inline void ite_clrtoeos(struct ite_softc *);
+static inline void ite_clrtobos(struct ite_softc *);
+static inline void ite_clrscreen(struct ite_softc *);
+static inline void ite_dnline(struct ite_softc *, int);
+static inline void ite_inline(struct ite_softc *, int);
+static inline void ite_index(struct ite_softc *);
+static inline void ite_lf(struct ite_softc *);
+static inline void ite_crlf(struct ite_softc *);
+static inline void ite_cr(struct ite_softc *);
+static inline void ite_rlf(struct ite_softc *);
 static void iteprecheckwrap(struct ite_softc *);
 static void itecheckwrap(struct ite_softc *);
 static int ite_argnum(struct ite_softc *);
 static int ite_zargnum(struct ite_softc *);
 static void ite_sendstr(struct ite_softc *, const char *);
-inline static int atoi(const char *);
-struct ite_softc *getitesp(dev_t);
+static inline int atoi(const char *);
+static struct ite_softc *getitesp(dev_t);
 
-struct itesw itesw[] = {
+static struct itesw itesw[] = {
 	{0,	tv_init,	tv_deinit,	0,
 	 0,	0,		0}
 };
@@ -134,35 +134,38 @@ struct itesw itesw[] = {
 #define ITEBURST 64
 
 struct	tty *ite_tty[NITE];
-struct	ite_softc *kbd_ite = NULL;
-struct  ite_softc con_itesoftc;
-struct	device con_itedev;
 
-struct  tty *kbd_tty = NULL;
+static struct ite_softc *kbd_ite = NULL;
+static struct ite_softc con_itesoftc;
+static struct device con_itedev;
 
-int	start_repeat_timeo = 20; /* /100: initial timeout till pressed key repeats */
-int	next_repeat_timeo  = 3;  /* /100: timeout when repeating for next char */
+static struct tty *kbd_tty = NULL;
 
-u_char	cons_tabs[MAX_TABS];
+static int start_repeat_timeo = 20;	/* /100: initial timeout till pressed
+						 key repeats */
+static int next_repeat_timeo  = 3;	/* /100: timeout when repeating for
+						 next char */
 
-void	itestart(struct tty *);
+static u_char cons_tabs[MAX_TABS];
 
-void iteputchar(int, struct ite_softc *);
-void ite_putstr(const u_char *, int, dev_t);
+static void itestart(struct tty *);
 
-int itematch(device_t, cfdata_t, void *);
-void iteattach(device_t, device_t, void *);
+static void iteputchar(int, struct ite_softc *);
+static void ite_putstr(const u_char *, int, dev_t);
+
+static int itematch(device_t, cfdata_t, void *);
+static void iteattach(device_t, device_t, void *);
 
 CFATTACH_DECL_NEW(ite, sizeof(struct ite_softc),
     itematch, iteattach, NULL, NULL);
 
-dev_type_open(iteopen);
-dev_type_close(iteclose);
-dev_type_read(iteread);
-dev_type_write(itewrite);
-dev_type_ioctl(iteioctl);
-dev_type_tty(itetty);
-dev_type_poll(itepoll);
+static dev_type_open(iteopen);
+static dev_type_close(iteclose);
+static dev_type_read(iteread);
+static dev_type_write(itewrite);
+static dev_type_ioctl(iteioctl);
+static dev_type_tty(itetty);
+static dev_type_poll(itepoll);
 
 const struct cdevsw ite_cdevsw = {
 	.d_open = iteopen,
@@ -179,7 +182,7 @@ const struct cdevsw ite_cdevsw = {
 	.d_flag = D_TTY
 };
 
-int
+static int
 itematch(device_t parent, cfdata_t cf, void *aux)
 {
 	struct grf_softc *gp;
@@ -195,7 +198,7 @@ itematch(device_t parent, cfdata_t cf, v
  * iteinit() is the standard entry point for initialization of
  * an ite device, it is also called from ite_cninit().
  */
-void
+static void
 iteattach(device_t parent, device_t self, void *aux)
 {
 	struct ite_softc *ip;
@@ -223,7 +226,7 @@ iteattach(device_t parent, device_t self
 	aprint_normal("\n");
 }
 
-struct ite_softc *
+static struct ite_softc *
 getitesp(dev_t dev)
 {
 
@@ -232,7 +235,7 @@ getitesp(dev_t dev)
 
 	if (con_itesoftc.grf == NULL)
 		panic("no ite_softc for console");
-	return(&con_itesoftc);
+	return &con_itesoftc;
 }
 
 void
@@ -254,8 +257,9 @@ iteinit(dev_t dev)
 	ip->isw = &itesw[device_unit(ip->device)]; /* XXX */
 	SUBR_INIT(ip);
 	SUBR_CURSOR(ip, DRAW_CURSOR);
-	if (!ip->tabs)
-		ip->tabs = malloc(MAX_TABS*sizeof(u_char), M_DEVBUF, M_WAITOK);
+	if (ip->tabs == NULL)
+		ip->tabs = malloc(MAX_TABS * sizeof(u_char),
+		    M_DEVBUF, M_WAITOK);
 	ite_reset(ip);
 	ip->flags |= ITE_INITED;
 }
@@ -282,29 +286,29 @@ iteon(dev_t dev, int flag)
 	struct ite_softc *ip;
 
 	if (unit < 0 || unit >= ite_cd.cd_ndevs ||
-	    (ip = getitesp(dev)) == NULL || (ip->flags&ITE_ALIVE) == 0)
-		return(ENXIO);
+	    (ip = getitesp(dev)) == NULL || (ip->flags & ITE_ALIVE) == 0)
+		return ENXIO;
 	/* force ite active, overriding graphics mode */
-	if (flag & 1) {
+	if ((flag & 1) != 0) {
 		ip->flags |= ITE_ACTIVE;
 		ip->flags &= ~(ITE_INGRF|ITE_INITED);
 	}
 	/* leave graphics mode */
-	if (flag & 2) {
+	if ((flag & 2) != 0) {
 		ip->flags &= ~ITE_INGRF;
 		if ((ip->flags & ITE_ACTIVE) == 0)
-			return(0);
+			return 0;
 	}
 	ip->flags |= ITE_ACTIVE;
-	if (ip->flags & ITE_INGRF)
-		return(0);
+	if ((ip->flags & ITE_INGRF) != 0)
+		return 0;
 	iteinit(dev);
-	if (flag & 2)
+	if ((flag & 2) != 0)
 		ite_reset(ip);
 #if NKBD > 0
 	mfp_send_usart(0x49);	/* XXX */
 #endif
-	return(0);
+	return 0;
 }
 
 /*
@@ -321,15 +325,15 @@ iteoff(dev_t dev, int flag)
 
 	/* XXX check whether when call from grf.c */
 	if (unit < 0 || unit >= ite_cd.cd_ndevs ||
-	    (ip = getitesp(dev)) == NULL || (ip->flags&ITE_ALIVE) == 0)
+	    (ip = getitesp(dev)) == NULL || (ip->flags & ITE_ALIVE) == 0)
 		return;
-	if (flag & 2)
+	if ((flag & 2) != 0)
 		ip->flags |= ITE_INGRF;
 
 	if ((ip->flags & ITE_ACTIVE) == 0)
 		return;
-	if ((flag & 1) ||
-	    (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
+	if ((flag & 1) != 0 ||
+	    (ip->flags & (ITE_INGRF | ITE_ISCONS | ITE_INITED)) == ITE_INITED)
 		SUBR_DEINIT(ip);
 
 	/*
@@ -352,7 +356,7 @@ iteoff(dev_t dev, int flag)
  */
 
 /* ARGSUSED */
-int
+static int
 iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
 {
 	int unit = UNIT(dev);
@@ -362,18 +366,18 @@ iteopen(dev_t dev, int mode, int devtype
 	int first = 0;
 
 	if (unit >= ite_cd.cd_ndevs || (ip = getitesp(dev)) == NULL)
-		return (ENXIO);
-	if (!ite_tty[unit]) {
+		return ENXIO;
+	if (ite_tty[unit] == NULL) {
 		tp = ite_tty[unit] = tty_alloc();
 		tty_attach(tp);
 	} else
 		tp = ite_tty[unit];
 	if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
-		return (EBUSY);
+		return EBUSY;
 	if ((ip->flags & ITE_ACTIVE) == 0) {
 		error = iteon(dev, 0);
 		if (error)
-			return (error);
+			return error;
 		first = 1;
 	}
 	tp->t_oproc = itestart;
@@ -395,11 +399,11 @@ iteopen(dev_t dev, int mode, int devtype
 		tp->t_winsize.ws_col = ip->cols;
 	} else if (first)
 		iteoff(dev, 0);
-	return (error);
+	return error;
 }
 
 /*ARGSUSED*/
-int
+static int
 iteclose(dev_t dev, int flag, int mode, struct lwp *l)
 {
 	struct tty *tp = ite_tty[UNIT(dev)];
@@ -409,43 +413,43 @@ iteclose(dev_t dev, int flag, int mode, 
 	iteoff(dev, 0);
 #if 0
 	tty_free(tp);
-	ite_tty[UNIT(dev)] = (struct tty *)0;
+	ite_tty[UNIT(dev)] = NULL;
 #endif
-	return(0);
+	return 0;
 }
 
-int
+static int
 iteread(dev_t dev, struct uio *uio, int flag)
 {
 	struct tty *tp = ite_tty[UNIT(dev)];
 
-	return ((*tp->t_linesw->l_read)(tp, uio, flag));
+	return (*tp->t_linesw->l_read)(tp, uio, flag);
 }
 
-int
+static int
 itewrite(dev_t dev, struct uio *uio, int flag)
 {
 	struct tty *tp = ite_tty[UNIT(dev)];
 
-	return ((*tp->t_linesw->l_write)(tp, uio, flag));
+	return (*tp->t_linesw->l_write)(tp, uio, flag);
 }
 
-int
+static int
 itepoll(dev_t dev, int events, struct lwp *l)
 {
 	struct tty *tp = ite_tty[UNIT(dev)];
 
-	return ((*tp->t_linesw->l_poll)(tp, events, l));
+	return (*tp->t_linesw->l_poll)(tp, events, l);
 }
 
-struct tty *
+static struct tty *
 itetty(dev_t dev)
 {
 
-	return (ite_tty[UNIT(dev)]);
+	return ite_tty[UNIT(dev)];
 }
 
-int
+static int
 iteioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
 {
 	struct iterepeat *irp;
@@ -454,24 +458,24 @@ iteioctl(dev_t dev, u_long cmd, void *ad
 
 	error = (*tp->t_linesw->l_ioctl)(tp, cmd, addr, flag, l);
 	if (error != EPASSTHROUGH)
-		return (error);
+		return error;
 
 	error = ttioctl(tp, cmd, addr, flag, l);
 	if (error != EPASSTHROUGH)
-		return (error);
+		return error;
 
 	switch (cmd) {
 	case ITEIOCSKMAP:
-		if (addr == 0)
-			return(EFAULT);
+		if (addr == NULL)
+			return EFAULT;
 		memcpy(&kbdmap, addr, sizeof(struct kbdmap));
-		return(0);
+		return 0;
 
 	case ITEIOCGKMAP:
 		if (addr == NULL)
-			return(EFAULT);
+			return EFAULT;
 		memcpy(addr, &kbdmap, sizeof(struct kbdmap));
-		return(0);
+		return 0;
 
 	case ITEIOCGREPT:
 		irp = (struct iterepeat *)addr;
@@ -486,7 +490,7 @@ iteioctl(dev_t dev, u_long cmd, void *ad
 		next_repeat_timeo = irp->next;
 #if x68k
 	case ITELOADFONT:
-		if (addr) {
+		if (addr != NULL) {
 			memcpy(kern_font, addr, 4096 /*sizeof(kernel_font)*/);
 			ite_set_glyph();
 			return 0;
@@ -494,21 +498,21 @@ iteioctl(dev_t dev, u_long cmd, void *ad
 			return EFAULT;
 
 	case ITETVCTRL:
-		if (addr && *(u_int8_t *)addr < 0x40) {
-			return mfp_send_usart(* (u_int8_t *)addr);
+		if (addr != NULL && *(uint8_t *)addr < 0x40) {
+			return mfp_send_usart(*(uint8_t *)addr);
 		} else {
 			return EFAULT;
 		}
 #endif
 	}
-	return (EPASSTHROUGH);
+	return EPASSTHROUGH;
 }
 
-void
+static void
 itestart(struct tty *tp)
 {
 	struct clist *rbp;
-	u_char buf[ITEBURST];
+	uint8_t buf[ITEBURST];
 	int s, len;
 
 	getitesp(tp->t_dev);
@@ -518,7 +522,7 @@ itestart(struct tty *tp)
 	 * state of our tty (kernel printf doesn't go through this routine).
 	 */
 	s = spltty();
-	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
+	if ((tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) != 0)
 		goto out;
 	tp->t_state |= TS_BUSY;
 	rbp = &tp->t_outq;
@@ -535,7 +539,7 @@ itestart(struct tty *tp)
 		tp->t_state |= TS_TIMEOUT;
 		callout_schedule(&tp->t_rstrt_ch, 1);
 	}
-out:
+ out:
 	splx(s);
 }
 
@@ -602,7 +606,7 @@ ite_cnfilter(u_char c)
 {
 	static u_char mod = 0;
 	struct key key;
-	u_char code, up, mask;
+	uint8_t code, up, mask;
 	int s;
 
 	up = c & 0x80 ? 1 : 0;
@@ -612,7 +616,8 @@ ite_cnfilter(u_char c)
 	s = spltty();
 
 	mask = 0;
-	if (c >= KBD_LEFT_ALT && !(c >= 0x63 && c <= 0x6c)) {	/* 0x63: F1, 0x6c:F10 */
+	if (c >= KBD_LEFT_ALT &&
+	    !(c >= 0x63 && c <= 0x6c)) {	/* 0x63: F1, 0x6c:F10 */
 		switch (c) {
 		case KBD_LEFT_SHIFT:
 			mask = KBD_MOD_SHIFT;
@@ -660,7 +665,8 @@ ite_cnfilter(u_char c)
 			}
 		} else if (up)
 			mod &= ~mask;
-		else mod |= mask;
+		else
+			mod |= mask;
 		splx(s);
 		return -1;
 	}
@@ -671,61 +677,63 @@ ite_cnfilter(u_char c)
 	}
 
 	/* translate modifiers */
-	if (mod & KBD_MOD_SHIFT) {
-		if (mod & KBD_MOD_ALT)
+	if ((mod & KBD_MOD_SHIFT) != 0) {
+		if ((mod & KBD_MOD_ALT) != 0)
 			key = kbdmap.alt_shift_keys[c];
 		else
 			key = kbdmap.shift_keys[c];
-	} else if (mod & KBD_MOD_ALT)
+	} else if ((mod & KBD_MOD_ALT) != 0)
 		key = kbdmap.alt_keys[c];
 	else {
 		key = kbdmap.keys[c];
 		/* if CAPS and key is CAPable (no pun intended) */
-		if ((mod & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
+		if ((mod & KBD_MOD_CAPS) != 0 &&
+		    (key.mode & KBD_MODE_CAPS) != 0)
 			key = kbdmap.shift_keys[c];
 	}
 	code = key.code;
 
 	/* if string return */
-	if (key.mode & (KBD_MODE_STRING | KBD_MODE_KPAD)) {
+	if ((key.mode & (KBD_MODE_STRING | KBD_MODE_KPAD)) != 0) {
 		splx(s);
 		return -1;
 	}
 	/* handle dead keys */
-	if (key.mode & KBD_MODE_DEAD) {
+	if ((key.mode & KBD_MODE_DEAD) != 0) {
 		splx(s);
 		return -1;
 	}
-	if (mod & KBD_MOD_CTRL)
+	if ((mod & KBD_MOD_CTRL) != 0)
 		code &= 0x1f;
-	if (mod & KBD_MOD_META)
+	if ((mod & KBD_MOD_META) != 0)
 		code |= 0x80;
 
 	/* do console mapping. */
 	code = code == '\r' ? '\n' : code;
 
 	splx(s);
-	return (code);
+	return code;
 }
 
 /* And now the old stuff. */
-inline static void
+static inline void
 itesendch(int ch)
 {
+
 	(*kbd_tty->t_linesw->l_rint)(ch, kbd_tty);
 }
 
-
 void
 ite_filter(u_char c)
 {
-	static u_short mod = 0;
-	unsigned char code, *str;
-	u_short up, mask;
+	static uint16_t mod = 0;
+	uint8_t code, *str;
+	uint16_t up, mask;
 	struct key key;
 	int s, i;
 
-	if (!kbd_ite || !(kbd_tty = ite_tty[device_unit(kbd_ite->device)]))
+	if (kbd_ite == NULL ||
+	    (kbd_tty = ite_tty[device_unit(kbd_ite->device)]) == NULL)
 		return;
 
 	/* have to make sure we're at spltty in here */
@@ -786,7 +794,7 @@ ite_filter(u_char c)
 			break;
 		}
 
-		if (mask & KBD_MOD_CAPS) {
+		if ((mask & KBD_MOD_CAPS) != 0) {
 			if (!up) {
 				mod ^= KBD_MOD_CAPS;
 				kbdled ^= LED_CAPS_LOCK;
@@ -794,7 +802,8 @@ ite_filter(u_char c)
 			}
 		} else if (up) {
 			mod &= ~mask;
-		} else mod |= mask;
+		} else
+			mod |= mask;
 
 		/*
 		 * return even if it wasn't a modifier key, the other
@@ -821,39 +830,41 @@ ite_filter(u_char c)
 	}
 
 	/* translate modifiers */
-	if (mod & KBD_MOD_SHIFT) {
-		if (mod & KBD_MOD_ALT)
+	if ((mod & KBD_MOD_SHIFT) != 0) {
+		if ((mod & KBD_MOD_ALT) != 0)
 			key = kbdmap.alt_shift_keys[c];
 		else
 			key = kbdmap.shift_keys[c];
-	} else if (mod & KBD_MOD_ALT)
+	} else if ((mod & KBD_MOD_ALT) != 0)
 		key = kbdmap.alt_keys[c];
 	else {
 		key = kbdmap.keys[c];
 		/* if CAPS and key is CAPable (no pun intended) */
-		if ((mod & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
+		if ((mod & KBD_MOD_CAPS) != 0 &&
+		    (key.mode & KBD_MODE_CAPS) != 0)
 			key = kbdmap.shift_keys[c];
-		else if ((mod & KBD_MOD_OPT2) && (key.mode & KBD_MODE_KPAD))
+		else if ((mod & KBD_MOD_OPT2) != 0 &&
+		    	 (key.mode & KBD_MODE_KPAD) != 0)
 			key = kbdmap.shift_keys[c];
 	}
 	code = key.code;
 
 	/* handle dead keys */
-	if (key.mode & KBD_MODE_DEAD) {
+	if ((key.mode & KBD_MODE_DEAD) != 0) {
 		splx(s);
 		return;
 	}
 	/* if not string, apply META and CTRL modifiers */
-	if (! (key.mode & KBD_MODE_STRING)
-	    && (!(key.mode & KBD_MODE_KPAD) ||
-		(kbd_ite && !kbd_ite->keypad_appmode))) {
-		if ((mod & KBD_MOD_CTRL) &&
+	if ((key.mode & KBD_MODE_STRING) == 0 &&
+	    ((key.mode & KBD_MODE_KPAD) == 0 ||
+	     (kbd_ite != NULL && kbd_ite->keypad_appmode == 0))) {
+		if ((mod & KBD_MOD_CTRL) != 0 &&
 		    (code == ' ' || (code >= '@' && code <= 'z')))
 			code &= 0x1f;
-		if (mod & KBD_MOD_META)
+		if ((mod & KBD_MOD_META) != 0)
 			code |= 0x80;
-	} else if ((key.mode & KBD_MODE_KPAD) &&
-	       (kbd_ite && kbd_ite->keypad_appmode)) {
+	} else if ((key.mode & KBD_MODE_KPAD) != 0 &&
+	       (kbd_ite != NULL && kbd_ite->keypad_appmode != 0)) {
 		static const char * const in = "0123456789-+.\r()/*";
 		static const char * const out = "pqrstuvwxymlnMPQRS";
 		char *cp = strchr(in, code);
@@ -869,12 +880,12 @@ ite_filter(u_char c)
 		return;
 	} else {
 		/* *NO* I don't like this.... */
-		static u_char app_cursor[] =
-		{
+		static u_char app_cursor[] = {
 		  3, 27, 'O', 'A',
 		  3, 27, 'O', 'B',
 		  3, 27, 'O', 'C',
-		  3, 27, 'O', 'D'};
+		  3, 27, 'O', 'D'
+		};
 
 		str = kbdmap.strings + code;
 		/*
@@ -882,9 +893,9 @@ ite_filter(u_char c)
 		 * keymap setting, AND we're in app-cursor mode, switch
 		 * to the above table. This is *nasty* !
 		 */
-		if (c >= 0x3b && c <= 0x3e && kbd_ite->cursor_appmode
-		    && !memcmp(str, "\x03\x1b[", 3) &&
-		    strchr("ABCD", str[3]))
+		if (c >= 0x3b && c <= 0x3e && kbd_ite->cursor_appmode != 0 &&
+		    memcmp(str, "\x03\x1b[", 3) == 0 &&
+		    strchr("ABCD", str[3]) != 0)
 			str = app_cursor + 4 * (str[3] - 'A');
 
 		/*
@@ -904,14 +915,15 @@ ite_filter(u_char c)
 }
 
 /* helper functions, makes the code below more readable */
-inline static void
+static inline void
 ite_sendstr(struct ite_softc *ip, const char *str)
 {
-	while (*str)
+
+	while (*str != 0)
 		itesendch(*str++);
 }
 
-inline static void
+static inline void
 alignment_display(struct ite_softc *ip)
 {
 	int i, j;
@@ -922,10 +934,11 @@ alignment_display(struct ite_softc *ip)
 	attrclr(ip, 0, 0, ip->rows, ip->cols);
 }
 
-inline static void
+static inline void
 snap_cury(struct ite_softc *ip)
 {
-	if (ip->inside_margins) {
+
+	if (ip->inside_margins != 0) {
 		if (ip->cury < ip->top_margin)
 			ip->cury = ip->top_margin;
 		if (ip->cury > ip->bottom_margin)
@@ -933,14 +946,15 @@ snap_cury(struct ite_softc *ip)
 	}
 }
 
-inline static void
+static inline void
 ite_dnchar(struct ite_softc *ip, int n)
 {
+
 	n = uimin(n, ip->cols - ip->curx);
 	if (n < ip->cols - ip->curx) {
 		SUBR_SCROLL(ip, ip->cury, ip->curx + n, n, SCROLL_LEFT);
 		attrmov(ip, ip->cury, ip->curx + n, ip->cury, ip->curx,
-			1, ip->cols - ip->curx - n);
+		    1, ip->cols - ip->curx - n);
 		attrclr(ip, ip->cury, ip->cols - n, 1, n);
 	}
 	while (n-- > 0)
@@ -951,58 +965,65 @@ static void
 ite_inchar(struct ite_softc *ip, int n)
 {
 	int c = ip->save_char;
+
 	ip->save_char = 0;
 	n = uimin(n, ip->cols - ip->curx);
 	if (n < ip->cols - ip->curx) {
 		SUBR_SCROLL(ip, ip->cury, ip->curx, n, SCROLL_RIGHT);
 		attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + n,
-			1, ip->cols - ip->curx - n);
+		    1, ip->cols - ip->curx - n);
 		attrclr(ip, ip->cury, ip->curx, 1, n);
 	}
-	while (n--)
+	while (n-- != 0)
 		SUBR_PUTC(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
 	ip->save_char = c;
 }
 
-inline static void
+static inline void
 ite_clrtoeol(struct ite_softc *ip)
 {
 	int y = ip->cury, x = ip->curx;
+
 	if (ip->cols - x > 0) {
 		SUBR_CLEAR(ip, y, x, 1, ip->cols - x);
 		attrclr(ip, y, x, 1, ip->cols - x);
 	}
 }
 
-inline static void
+static inline void
 ite_clrtobol(struct ite_softc *ip)
 {
 	int y = ip->cury, x = uimin(ip->curx + 1, ip->cols);
+
 	SUBR_CLEAR(ip, y, 0, 1, x);
 	attrclr(ip, y, 0, 1, x);
 }
 
-inline static void
+static inline void
 ite_clrline(struct ite_softc *ip)
 {
 	int y = ip->cury;
+
 	SUBR_CLEAR(ip, y, 0, 1, ip->cols);
 	attrclr(ip, y, 0, 1, ip->cols);
 }
 
-inline static void
+static inline void
 ite_clrtoeos(struct ite_softc *ip)
 {
+
 	ite_clrtoeol(ip);
 	if (ip->cury < ip->rows - 1) {
-		SUBR_CLEAR(ip, ip->cury + 1, 0, ip->rows - 1 - ip->cury, ip->cols);
+		SUBR_CLEAR(ip, ip->cury + 1, 0,
+		    ip->rows - 1 - ip->cury, ip->cols);
 		attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
 	}
 }
 
-inline static void
+static inline void
 ite_clrtobos(struct ite_softc *ip)
 {
+
 	ite_clrtobol(ip);
 	if (ip->cury > 0) {
 		SUBR_CLEAR(ip, 0, 0, ip->cury, ip->cols);
@@ -1010,18 +1031,18 @@ ite_clrtobos(struct ite_softc *ip)
 	}
 }
 
-inline static void
+static inline void
 ite_clrscreen(struct ite_softc *ip)
 {
+
 	SUBR_CLEAR(ip, 0, 0, ip->rows, ip->cols);
 	attrclr(ip, 0, 0, ip->rows, ip->cols);
 }
 
-
-
-inline static void
+static inline void
 ite_dnline(struct ite_softc *ip, int n)
 {
+
 	/*
 	 * interesting.. if the cursor is outside the scrolling
 	 * region, this command is simply ignored..
@@ -1033,15 +1054,16 @@ ite_dnline(struct ite_softc *ip, int n)
 	if (n <= ip->bottom_margin - ip->cury) {
 		SUBR_SCROLL(ip, ip->cury + n, 0, n, SCROLL_UP);
 		attrmov(ip, ip->cury + n, 0, ip->cury, 0,
-			ip->bottom_margin + 1 - ip->cury - n, ip->cols);
+		    ip->bottom_margin + 1 - ip->cury - n, ip->cols);
 	}
 	SUBR_CLEAR(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
 	attrclr(ip, ip->bottom_margin - n + 1, 0, n, ip->cols);
 }
 
-inline static void
+static inline void
 ite_inline(struct ite_softc *ip, int n)
 {
+
 	/*
 	 * interesting.. if the cursor is outside the scrolling
 	 * region, this command is simply ignored..
@@ -1051,20 +1073,22 @@ ite_inline(struct ite_softc *ip, int n)
 
 	if (n <= 0)
 		n = 1;
-	else n = uimin(n, ip->bottom_margin + 1 - ip->cury);
+	else
+		n = uimin(n, ip->bottom_margin + 1 - ip->cury);
 	if (n <= ip->bottom_margin  - ip->cury) {
 		SUBR_SCROLL(ip, ip->cury, 0, n, SCROLL_DOWN);
 		attrmov(ip, ip->cury, 0, ip->cury + n, 0,
-			ip->bottom_margin + 1 - ip->cury - n, ip->cols);
+		    ip->bottom_margin + 1 - ip->cury - n, ip->cols);
 	}
 	SUBR_CLEAR(ip, ip->cury, 0, n, ip->cols);
 	attrclr(ip, ip->cury, 0, n, ip->cols);
 	ip->curx = 0;
 }
 
-inline static void
+static inline void
 ite_index(struct ite_softc *ip)
 {
+
 	++ip->cury;
 	if ((ip->cury == ip->bottom_margin+1) || (ip->cury == ip->rows)) {
 		ip->cury--;
@@ -1074,16 +1098,17 @@ ite_index(struct ite_softc *ip)
 	/*clr_attr(ip, ATTR_INV);*/
 }
 
-inline static void
+static inline void
 ite_lf(struct ite_softc *ip)
 {
+
 	++ip->cury;
 	if (ip->cury > ip->bottom_margin) {
 		ip->cury--;
 		SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
 		ite_clrline(ip);
 	}
-/*	SUBR_CURSOR(ip, MOVE_CURSOR);*/
+	/*SUBR_CURSOR(ip, MOVE_CURSOR);*/
 	/*clr_attr(ip, ATTR_INV);*/
 	/* reset character set ... thanks for mohta. */
 	ip->G0 = CSET_ASCII;
@@ -1096,24 +1121,27 @@ ite_lf(struct ite_softc *ip)
 	ip->save_char = 0;
 }
 
-inline static void
+static inline void
 ite_crlf(struct ite_softc *ip)
 {
+
 	ip->curx = 0;
-	ite_lf (ip);
+	ite_lf(ip);
 }
 
-inline static void
+static inline void
 ite_cr(struct ite_softc *ip)
 {
-	if (ip->curx) {
+
+	if (ip->curx != 0) {
 		ip->curx = 0;
 	}
 }
 
-inline static void
+static inline void
 ite_rlf(struct ite_softc *ip)
 {
+
 	ip->cury--;
 	if ((ip->cury < 0) || (ip->cury == ip->top_margin - 1)) {
 		ip->cury++;
@@ -1123,7 +1151,7 @@ ite_rlf(struct ite_softc *ip)
 	clr_attr(ip, ATTR_INV);
 }
 
-inline static int
+static inline int
 atoi(const char *cp)
 {
 	int n;
@@ -1133,7 +1161,7 @@ atoi(const char *cp)
 	return n;
 }
 
-inline static int
+static inline int
 ite_argnum(struct ite_softc *ip)
 {
 	char ch;
@@ -1150,7 +1178,7 @@ ite_argnum(struct ite_softc *ip)
 	return n;
 }
 
-inline static int
+static inline int
 ite_zargnum(struct ite_softc *ip)
 {
 	char ch;
@@ -1167,7 +1195,7 @@ ite_zargnum(struct ite_softc *ip)
 	return n;	/* don't "n ? n : 1" here, <CSI>0m != <CSI>1m ! */
 }
 
-void
+static void
 ite_putstr(const u_char *s, int len, dev_t dev)
 {
 	struct ite_softc *ip;
@@ -1181,28 +1209,35 @@ ite_putstr(const u_char *s, int len, dev
 
 	SUBR_CURSOR(ip, START_CURSOROPT);
 	for (i = 0; i < len; i++)
-		if (s[i])
+		if (s[i] != 0)
 			iteputchar(s[i], ip);
 	SUBR_CURSOR(ip, END_CURSOROPT);
 }
 
-void
+static void
 iteputchar(int c, struct ite_softc *ip)
 {
 	int n, x, y;
 	char *cp;
 
-	if (c >= 0x20 && ip->escape) {
+	if (c >= 0x20 && ip->escape != 0) {
 		switch (ip->escape) {
 
 		case ESC:
 			switch (c) {
-				/* first 7bit equivalents for the 8bit control characters */
+			/*
+			 * first 7bit equivalents for the 8bit control
+			 * characters
+			 */
 
 			case 'D':
 				c = IND;
 				ip->escape = 0;
-				break; /* and fall into the next switch below (same for all `break') */
+				break;
+				/*
+				 * and fall into the next switch below
+				 * (same for all `break')
+				 */
 
 			case 'E':
 				/* next line */
@@ -1266,16 +1301,14 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				break;
 
-
 			/* introduces 7/8bit control */
 			case ' ':
 				/* can be followed by either F or G */
 				ip->escape = ' ';
 				break;
 
-
-			/* a lot of character set selections, not yet used...
-			   94-character sets: */
+			/* a lot of character set selections, not yet used... */
+			/* 94-character sets: */
 			case '(':	/* G0 */
 			case ')':	/* G1 */
 				ip->escape = c;
@@ -1356,7 +1389,6 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case '7':
 				/* save cursor */
 				ip->save_curx = ip->curx;
@@ -1401,10 +1433,13 @@ iteputchar(int c, struct ite_softc *ip)
 				return;
 
 			case 'Z':	/* request ID */
-				if (ip->emul_level == EMUL_VT100)
-					ite_sendstr(ip, "\033[61;0c"); /* XXX not clean */
-				else
-					ite_sendstr(ip, "\033[63;0c"); /* XXX not clean */
+				if (ip->emul_level == EMUL_VT100) {
+					/* XXX not clean */
+					ite_sendstr(ip, "\033[61;0c");
+				} else {
+					/* XXX not clean */
+					ite_sendstr(ip, "\033[63;0c");
+				}
 				ip->escape = 0;
 				return;
 
@@ -1415,7 +1450,6 @@ iteputchar(int c, struct ite_softc *ip)
 			}
 			break;
 
-
 		case '(': /* designate G0 */
 			switch (c) {
 			case 'B': /* USASCII */
@@ -1430,6 +1464,10 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->G0 = CSET_JISROMA;
 				ip->escape = 0;
 				return;
+			case '0': /* dec special graphics */
+				ip->G0 = CSET_DECGRAPH;
+				ip->escape = 0;
+				return;
 			case 'A': /* British or ISO-Latin-1 */
 			case 'H': /* Swedish */
 			case 'K': /* German */
@@ -1443,7 +1481,34 @@ iteputchar(int c, struct ite_softc *ip)
 			}
 
 		case ')': /* designate G1 */
-			ip->escape = 0;
+			switch (c) {
+			case 'B': /* USASCII */
+				ip->G1 = CSET_ASCII;
+				ip->escape = 0;
+				return;
+			case 'I':
+				ip->G1 = CSET_JISKANA;
+				ip->escape = 0;
+				return;
+			case 'J':
+				ip->G1 = CSET_JISROMA;
+				ip->escape = 0;
+				return;
+			case '0': /* dec special graphics */
+				ip->G1 = CSET_DECGRAPH;
+				ip->escape = 0;
+				return;
+			case 'A': /* British or ISO-Latin-1 */
+			case 'H': /* Swedish */
+			case 'K': /* German */
+			case 'R': /* French */
+			case 'Y': /* Italian */
+			case 'Z': /* Spanish */
+			default:
+				/* not supported */
+				ip->escape = 0;
+				return;
+			}
 			return;
 
 		case '$': /* 94-multibyte character set */
@@ -1519,14 +1584,23 @@ iteputchar(int c, struct ite_softc *ip)
 			}
 			break;
 
-
-
 		case CSI:
 			/* the biggie... */
 			switch (c) {
-			case '0': case '1': case '2': case '3': case '4':
-			case '5': case '6': case '7': case '8': case '9':
-			case ';': case '\"': case '$': case '>':
+			case '0':
+			case '1':
+			case '2':
+			case '3':
+			case '4':
+			case '5':
+			case '6':
+			case '7':
+			case '8':
+			case '9':
+			case ';':
+			case '\"':
+			case '$':
+			case '>':
 				if (ip->ap < ip->argbuf + MAX_ARGSIZE)
 					*ip->ap++ = c;
 				return;
@@ -1535,44 +1609,50 @@ iteputchar(int c, struct ite_softc *ip)
 				*ip->ap = 0;
 				if (!strncmp(ip->argbuf, "61\"", 3))
 					ip->emul_level = EMUL_VT100;
-				else if (!strncmp(ip->argbuf, "63;1\"", 5)
-					 || !strncmp(ip->argbuf, "62;1\"", 5))
+				else if (!strncmp(ip->argbuf, "63;1\"", 5) ||
+					 !strncmp(ip->argbuf, "62;1\"", 5))
 					ip->emul_level = EMUL_VT300_7;
 				else
 					ip->emul_level = EMUL_VT300_8;
 				ip->escape = 0;
 				return;
 
-
 			case '?':
 				*ip->ap = 0;
 				ip->escape = '?';
 				ip->ap = ip->argbuf;
 				return;
 
-
 			case 'c':
 				/* device attributes */
 				*ip->ap = 0;
 				if (ip->argbuf[0] == '>') {
 					ite_sendstr(ip, "\033[>24;0;0;0c");
-				} else
+				} else {
 					switch (ite_zargnum(ip)) {
 					case 0:
-						/* primary DA request, send primary DA response */
-						if (ip->emul_level == EMUL_VT100)
-							ite_sendstr(ip, "\033[?1;1c");
+						/*
+						 * primary DA request, send
+						 * primary DA response
+						 */
+						if (ip->emul_level ==
+						    EMUL_VT100)
+							ite_sendstr(ip,
+							    "\033[?1;1c");
 						else
-							ite_sendstr(ip, "\033[63;0c");
+							ite_sendstr(ip,
+							    "\033[63;0c");
 						break;
 					}
+				}
 				ip->escape = 0;
 				return;
 
 			case 'n':
 				switch (ite_zargnum(ip)) {
 				case 5:
-					ite_sendstr(ip, "\033[0n");	/* no malfunction */
+					/* no malfunction */
+					ite_sendstr(ip, "\033[0n");
 					break;
 				case 6:
 					/* cursor position report */
@@ -1585,21 +1665,21 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case 'x':
 				switch (ite_zargnum(ip)) {
 				case 0:
 					/* Fake some terminal parameters.  */
-					ite_sendstr(ip, "\033[2;1;1;112;112;1;0x");
+					ite_sendstr(ip,
+					    "\033[2;1;1;112;112;1;0x");
 					break;
 				case 1:
-					ite_sendstr(ip, "\033[3;1;1;112;112;1;0x");
+					ite_sendstr(ip,
+					    "\033[3;1;1;112;112;1;0x");
 					break;
 				}
 				ip->escape = 0;
 				return;
 
-
 			case 'g':
 				/* clear tabs */
 				switch (ite_zargnum(ip)) {
@@ -1619,13 +1699,13 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case 'h': /* set mode */
 			case 'l': /* reset mode */
 				n = ite_zargnum(ip);
 				switch (n) {
 				case 4:
-					ip->imode = (c == 'h');	/* insert/replace mode */
+					/* insert/replace mode */
+					ip->imode = (c == 'h');
 					break;
 				case 20:
 					ip->linefeed_newline = (c == 'h');
@@ -1634,28 +1714,24 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case 'M':
 				/* delete line */
 				ite_dnline(ip, ite_argnum(ip));
 				ip->escape = 0;
 				return;
 
-
 			case 'L':
 				/* insert line */
 				ite_inline(ip, ite_argnum(ip));
 				ip->escape = 0;
 				return;
 
-
 			case 'P':
 				/* delete char */
 				ite_dnchar(ip, ite_argnum(ip));
 				ip->escape = 0;
 				return;
 
-
 			case '@':
 				/* insert char(s) */
 				ite_inchar(ip, ite_argnum(ip));
@@ -1668,12 +1744,15 @@ iteputchar(int c, struct ite_softc *ip)
 				return;
 
 			case 'G':
-				/* this one was *not* in my vt320 manual but in
-				   a vt320 termcap entry.. who is right?
-				   It's supposed to set the horizontal cursor position. */
+				/*
+				 * this one was *not* in my vt320 manual but
+				 * in a vt320 termcap entry.. who is right?
+				 * It's supposed to set the horizontal cursor
+				 * position.
+				 */
 				*ip->ap = 0;
 				x = atoi(ip->argbuf);
-				if (x)
+				if (x != 0)
 					x--;
 				ip->curx = uimin(x, ip->cols - 1);
 				ip->escape = 0;
@@ -1681,10 +1760,12 @@ iteputchar(int c, struct ite_softc *ip)
 				clr_attr(ip, ATTR_INV);
 				return;
 
-
 			case 'd':
-				/* same thing here, this one's for setting the absolute
-				   vertical cursor position. Not documented... */
+				/*
+				 * same thing here, this one's for setting
+				 * the absolute vertical cursor position.
+				 * Not documented...
+				 */
 				*ip->ap = 0;
 				y = atoi(ip->argbuf);
 				if (y)
@@ -1698,20 +1779,19 @@ iteputchar(int c, struct ite_softc *ip)
 				clr_attr(ip, ATTR_INV);
 				return;
 
-
 			case 'H':
 			case 'f':
 				*ip->ap = 0;
 				y = atoi(ip->argbuf);
 				x = 0;
 				cp = strchr(ip->argbuf, ';');
-				if (cp)
+				if (cp != NULL)
 					x = atoi(cp + 1);
-				if (x)
+				if (x != 0)
 					x--;
-				if (y)
+				if (y != 0)
 					y--;
-				if (ip->inside_margins)
+				if (ip->inside_margins != 0)
 					y += ip->top_margin;
 				ip->cury = uimin(y, ip->rows - 1);
 				ip->curx = uimin(x, ip->cols - 1);
@@ -1730,8 +1810,11 @@ iteputchar(int c, struct ite_softc *ip)
 				if (ip->inside_margins)
 					n = uimax(ip->top_margin, n);
 				else if (n == ip->top_margin - 1)
-					/* allow scrolling outside region, but don't scroll out
-					   of active region without explicit CUP */
+					/*
+					 * allow scrolling outside region,
+					 * but don't scroll out of active
+					 * region without explicit CUP
+					 */
 					n = ip->top_margin;
 				ip->cury = n;
 				ip->escape = 0;
@@ -1750,8 +1833,11 @@ iteputchar(int c, struct ite_softc *ip)
 					n = uimin(ip->bottom_margin, n);
 #if 0
 				else if (n == ip->bottom_margin + 1)
-					/* allow scrolling outside region, but don't scroll out
-					   of active region without explicit CUP */
+					/*
+					 * allow scrolling outside region,
+					 * but don't scroll out of active
+					 * region without explicit CUP
+					 */
 					n = ip->bottom_margin;
 #endif
 				ip->cury = n;
@@ -1781,7 +1867,6 @@ iteputchar(int c, struct ite_softc *ip)
 				clr_attr(ip, ATTR_INV);
 				return;
 
-
 			case 'J':
 				/* erase screen */
 				*ip->ap = 0;
@@ -1795,7 +1880,6 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case 'K':
 				/* erase line */
 				n = ite_zargnum(ip);
@@ -1835,13 +1919,14 @@ iteputchar(int c, struct ite_softc *ip)
 				n = ite_argnum(ip) - 1;
 				n = uimin(n, ip->cols - 1 - ip->curx);
 				for (; n >= 0; n--) {
-					attrclr(ip, ip->cury, ip->curx + n, 1, 1);
-					SUBR_PUTC(ip, ' ', ip->cury, ip->curx + n, ATTR_NOR);
+					attrclr(ip, ip->cury, ip->curx + n,
+					    1, 1);
+					SUBR_PUTC(ip, ' ',
+					    ip->cury, ip->curx + n, ATTR_NOR);
 				}
 				ip->escape = 0;
 				return;
 
-
 			case '}': case '`':
 				/* status line control */
 				ip->escape = 0;
@@ -1872,11 +1957,11 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->curx = 0;
 				return;
 
-
 			case 'm':
 				/* big attribute setter/resetter */
 			{
 				char *c_p;
+
 				*ip->ap = 0;
 				/* kludge to make CSIm work (== CSI0m) */
 				if (ip->ap == ip->argbuf)
@@ -1909,7 +1994,8 @@ iteputchar(int c, struct ite_softc *ip)
 							break;
 
 						case '5':
-							clr_attr(ip, ATTR_BLINK);
+							clr_attr(ip,
+							    ATTR_BLINK);
 							c_p += 2;
 							break;
 
@@ -1926,10 +2012,17 @@ iteputchar(int c, struct ite_softc *ip)
 
 					case '3':
 						switch (c_p[1]) {
-						case '0': case '1': case '2': case '3':
-						case '4': case '5': case '6': case '7':
+						case '0':
+						case '1':
+						case '2':
+						case '3':
+						case '4':
+						case '5':
+						case '6':
+						case '7':
 							/* foreground colors */
-							ip->fgcolor = c_p[1] - '0';
+							ip->fgcolor =
+							    c_p[1] - '0';
 							c_p += 2;
 							break;
 						default:
@@ -1940,10 +2033,17 @@ iteputchar(int c, struct ite_softc *ip)
 
 					case '4':
 						switch (c_p[1]) {
-						case '0': case '1': case '2': case '3':
-						case '4': case '5': case '6': case '7':
+						case '0':
+						case '1':
+						case '2':
+						case '3':
+						case '4':
+						case '5':
+						case '6':
+						case '7':
 							/* background colors */
-							ip->bgcolor = c_p[1] - '0';
+							ip->bgcolor =
+							    c_p[1] - '0';
 							c_p += 2;
 							break;
 						default:
@@ -1973,7 +2073,6 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case 'u':
 				/* DECRQTSR */
 				ite_sendstr(ip, "\033P\033\\");
@@ -1986,20 +2085,29 @@ iteputchar(int c, struct ite_softc *ip)
 			}
 			break;
 
-
-
 		case '?':	/* CSI ? */
 			switch (c) {
-			case '0': case '1': case '2': case '3': case '4':
-			case '5': case '6': case '7': case '8': case '9':
-			case ';': case '\"': case '$':
-				/* Don't fill the last character; it's needed.  */
+			case '0':
+			case '1':
+			case '2':
+			case '3':
+			case '4':
+			case '5':
+			case '6':
+			case '7':
+			case '8':
+			case '9':
+			case ';':
+			case '\"':
+			case '$':
+				/*
+				 * Don't fill the last character; it's needed.
+				 */
 				/* XXX yeah, where ?? */
 				if (ip->ap < ip->argbuf + MAX_ARGSIZE - 1)
 					*ip->ap++ = c;
 				return;
 
-
 			case 'n':
 				/* Terminal Reports */
 				*ip->ap = 0;
@@ -2007,11 +2115,9 @@ iteputchar(int c, struct ite_softc *ip)
 					if (!strncmp(ip->argbuf, "15", 2))
 						/* printer status: no printer */
 						ite_sendstr(ip, "\033[13n");
-
 					else if (!strncmp(ip->argbuf, "25", 2))
 						/* udk status */
 						ite_sendstr(ip, "\033[20n");
-
 					else if (!strncmp(ip->argbuf, "26", 2))
 						/* keyboard dialect: US */
 						ite_sendstr(ip, "\033[27;1n");
@@ -2019,7 +2125,6 @@ iteputchar(int c, struct ite_softc *ip)
 				ip->escape = 0;
 				return;
 
-
 			case 'h': /* set dec private modes */
 			case 'l': /* reset dec private modes */
 				n = ite_zargnum(ip);
@@ -2037,14 +2142,18 @@ iteputchar(int c, struct ite_softc *ip)
 					break;
 
 				case 5:
-					/* light background (=='h') /dark background(=='l') */
+					/*
+					 * light background (=='h') /
+					 * dark background (=='l')
+					 */
 					break;
 
 				case 6: /* origin mode */
 					ip->inside_margins = (c == 'h');
 #if 0
 					ip->curx = 0;
-					ip->cury = ip->inside_margins ? ip->top_margin : 0;
+					ip->cury = ip->inside_margins ?
+					    ip->top_margin : 0;
 					SUBR_CURSOR(ip, MOVE_CURSOR);
 #endif
 					break;
@@ -2062,7 +2171,8 @@ iteputchar(int c, struct ite_softc *ip)
 					break;
 
 				case 25: /* cursor on/off */
-					SUBR_CURSOR(ip, (c == 'h') ? DRAW_CURSOR : ERASE_CURSOR);
+					SUBR_CURSOR(ip, (c == 'h') ?
+					    DRAW_CURSOR : ERASE_CURSOR);
 					break;
 				}
 				ip->escape = 0;
@@ -2079,7 +2189,6 @@ iteputchar(int c, struct ite_softc *ip)
 			}
 			break;
 
-
 		default:
 			ip->escape = 0;
 			return;
@@ -2123,8 +2232,10 @@ iteputchar(int c, struct ite_softc *ip)
 	case VT:	/* VT is treated like LF */
 	case FF:	/* so is FF */
 	case LF:
-		/* cr->crlf distinction is done here, on output,
-		   not on input! */
+		/*
+		 * cr->crlf distinction is done here, on output,
+		 * not on input!
+		 */
 		if (ip->linefeed_newline)
 			ite_crlf(ip);
 		else
@@ -2135,7 +2246,6 @@ iteputchar(int c, struct ite_softc *ip)
 		ite_cr(ip);
 		break;
 
-
 	case SO:
 		ip->GL = &ip->G1;
 		break;
@@ -2218,15 +2328,18 @@ iteputchar(int c, struct ite_softc *ip)
 		/* ignore, if not used as terminator */
 		break;
 		
-	case OSC:	/* introduces OS command. Ignore everything upto ST */
+	case OSC:	/* introduces OS command. */
+		/* Ignore everything upto ST */
 		ip->escape = OSC;
 		break;
 
-	case PM:	/* privacy message, ignore everything upto ST */
+	case PM:	/* privacy message */
+		/* ignore everything upto ST */
 		ip->escape = PM;
 		break;
 		
-	case APC:	/* application program command, ignore everything upto ST */
+	case APC:	/* application program command */
+		/* ignore everything upto ST */
 		ip->escape = APC;
 		break;
 
@@ -2234,11 +2347,12 @@ iteputchar(int c, struct ite_softc *ip)
 		break;
 
 	default:
-		if (!ip->save_char && (*((c & 0x80) ? ip->GR : ip->GL) & CSET_MULTI)) {
+		if (ip->save_char == 0 &&
+		    (*((c & 0x80) ? ip->GR : ip->GL) & CSET_MULTI) != 0) {
 			ip->save_char = c;
 			break;
 		}
-		if (ip->imode)
+		if (ip->imode != 0)
 			ite_inchar(ip, ip->save_char ? 2 : 1);
 		iteprecheckwrap(ip);
 #ifdef DO_WEIRD_ATTRIBUTES
@@ -2251,7 +2365,7 @@ iteputchar(int c, struct ite_softc *ip)
 #else
 		SUBR_PUTC(ip, c, ip->cury, ip->curx, ip->attribute);
 #endif
-/*		SUBR_CURSOR(ip, DRAW_CURSOR);*/
+		/*SUBR_CURSOR(ip, DRAW_CURSOR);*/
 		itecheckwrap(ip);
 		if (ip->save_char) {
 			itecheckwrap(ip);
@@ -2271,6 +2385,7 @@ iteputchar(int c, struct ite_softc *ip)
 static void
 iteprecheckwrap(struct ite_softc *ip)
 {
+
 	if (ip->auto_wrap && ip->curx + (ip->save_char ? 1 : 0) == ip->cols) {
 		ip->curx = 0;
 		clr_attr(ip, ATTR_INV);
@@ -2287,6 +2402,7 @@ iteprecheckwrap(struct ite_softc *ip)
 static void
 itecheckwrap(struct ite_softc *ip)
 {
+
 #if 0
 	if (++ip->curx == ip->cols) {
 		if (ip->auto_wrap) {
@@ -2295,7 +2411,8 @@ itecheckwrap(struct ite_softc *ip)
 			if (++ip->cury >= ip->bottom_margin + 1) {
 				ip->cury = ip->bottom_margin;
 				SUBR_CURSOR(ip, MOVE_CURSOR);
-				SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1, SCROLL_UP);
+				SUBR_SCROLL(ip, ip->top_margin + 1, 0, 1,
+				    SCROLL_UP);
 				ite_clrtoeol(ip);
 				return;
 			}
@@ -2311,6 +2428,62 @@ itecheckwrap(struct ite_softc *ip)
 #endif
 }
 
+/*
+ * A convertion table from DEC special graphics characters to ASCII characters.
+ * Mostly for box drawing on sysinst(8).
+ */
+const uint8_t ite_decgraph2ascii[128] = {
+	/* same as ASCII from 0x00 to 0x5e */
+	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+	0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+	0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+	0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+	0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+	0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e,
+
+	/* special graphics characters from 0x5f to 0x7e */
+	' ',	/* 0x5f NBSP */
+	'*',	/* 0x60 diamond */
+	' ',	/* 0x61 medium shade */
+	' ',	/* 0x62 HT */
+	' ',	/* 0x63 FF */
+	' ',	/* 0x64 CR */
+	' ',	/* 0x65 LF */
+	' ',	/* 0x66 degree symbol */
+	' ',	/* 0x67 plus-minus sign */
+	' ',	/* 0x68 NL */
+	' ',	/* 0x69 VT */
+	'+',	/* 0x6a box drawings up left */
+	'+',	/* 0x6b box drawings down left */
+	'+',	/* 0x6c box drawings down right */
+	'+',	/* 0x6d box drawings up right */
+	'+',	/* 0x6e box drawings vertical horizontal */
+	'~',	/* 0x6f scan line 1 */
+	'-',	/* 0x70 scan line 3 */
+	'-',	/* 0x71 scan line 5 */
+	'-',	/* 0x72 scan line 7 */
+	'_',	/* 0x73 scan line 9 */
+	'+',	/* 0x74 box drawings vertical right */
+	'+',	/* 0x75 box drawings vertical left */
+	'+',	/* 0x76 box drawings horizontal up */
+	'+',	/* 0x77 box drawings horizontal down */
+	'|',	/* 0x78 box drawings vertical */
+	'<',	/* 0x79 less than or equal to */
+	'>',	/* 0x7a greater than or equal to */
+	' ',	/* 0x7b pi */
+	' ',	/* 0x7c not equal */
+	' ',	/* 0x7d pound sign */
+	'.',	/* 0x7e middle dot */
+	/* end of special graphics characters */
+	0x7f
+};
+
 #endif
 
 #if NITE > 0 && NKBD > 0
@@ -2350,7 +2523,6 @@ itecnprobe(struct consdev *cd)
 		cd->cn_pri = CN_INTERNAL;
 		cd->cn_dev = makedev(maj, 0);
 	}
-
 }
 
 void

Index: src/sys/arch/x68k/dev/ite_tv.c
diff -u src/sys/arch/x68k/dev/ite_tv.c:1.17 src/sys/arch/x68k/dev/ite_tv.c:1.18
--- src/sys/arch/x68k/dev/ite_tv.c:1.17	Thu Feb  8 09:05:18 2018
+++ src/sys/arch/x68k/dev/ite_tv.c	Sat Jun 25 03:18:38 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ite_tv.c,v 1.17 2018/02/08 09:05:18 dholland Exp $	*/
+/*	$NetBSD: ite_tv.c,v 1.18 2022/06/25 03:18:38 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1997 Masaru Oki.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ite_tv.c,v 1.17 2018/02/08 09:05:18 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ite_tv.c,v 1.18 2022/06/25 03:18:38 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -69,39 +69,38 @@ __KERNEL_RCSID(0, "$NetBSD: ite_tv.c,v 1
 #define ROWBYTES    (PLANEWIDTH  / FONTWIDTH)
 #define PLANESIZE   (PLANEHEIGHT * ROWBYTES)
 
-u_int  tv_top;
-u_char *tv_row[PLANELINES];
-char   *tv_font[256];
-volatile char *tv_kfont[0x7f];
+static u_int  tv_top;
+static uint8_t *tv_row[PLANELINES];
+static uint8_t *tv_font[256];
+static volatile uint8_t *tv_kfont[0x7f];
 
-u_char kern_font[256 * FONTHEIGHT];
+uint8_t kern_font[256 * FONTHEIGHT];
 
 #define PHYSLINE(y)  ((tv_top + (y)) % PLANELINES)
 #define ROWOFFSET(y) ((y) * FONTHEIGHT * ROWBYTES)
 #define CHADDR(y, x) (tv_row[PHYSLINE(y)] + (x))
 
-#define SETGLYPH(to,from) memcpy(&kern_font[(from)*16],&kern_font[(to)*16], 16)
+#define SETGLYPH(to,from)	\
+	memcpy(&kern_font[(from) * 16],&kern_font[(to) * 16], 16)
 #define KFONTBASE(left)   ((left) * 32 * 0x5e - 0x21 * 32)
 
 /* prototype */
-void tv_init(struct ite_softc *);
-void tv_deinit(struct ite_softc *);
-void tv_putc(struct ite_softc *, int, int, int, int);
-void tv_cursor(struct ite_softc *, int);
-void tv_clear(struct ite_softc *, int, int, int, int);
-void tv_scroll(struct ite_softc *, int, int, int, int);
+static void tv_putc(struct ite_softc *, int, int, int, int);
+static void tv_cursor(struct ite_softc *, int);
+static void tv_clear(struct ite_softc *, int, int, int, int);
+static void tv_scroll(struct ite_softc *, int, int, int, int);
 
-inline static int expbits(int);
-inline static void txrascpy(u_char, u_char, short, signed short);
+static inline uint32_t expbits(uint32_t);
+static inline void txrascpy(uint8_t, uint8_t, int16_t, uint16_t);
 
 static inline void
-txrascpy(u_char src, u_char dst, short size, short mode)
+txrascpy(uint8_t src, uint8_t dst, int16_t size, uint16_t mode)
 {
 	/*int s;*/
-	u_short saved_r21 = CRTC.r21;
-	char d;
+	uint16_t saved_r21 = CRTC.r21;
+	int8_t d;
 
-	d = (mode < 0) ? -1 : 1;
+	d = ((mode & 0x8000) != 0) ? -1 : 1;
 	src *= FONTHEIGHT / 4;
 	dst *= FONTHEIGHT / 4;
 	size *= 4;
@@ -117,10 +116,10 @@ txrascpy(u_char src, u_char dst, short s
 	/*s = splhigh();*/
 	while (--size >= 0) {
 		/* wait for hsync */
-		mfp_wait_for_hsync ();
+		mfp_wait_for_hsync();
 		CRTC.r22 = (src << 8) | dst;	/* specify raster number */
 		/* start raster copy */
-		CRTC.crtctrl = 8;
+		CRTC.crtctrl = 0x0008;
 
 		src += d;
 		dst += d;
@@ -128,10 +127,10 @@ txrascpy(u_char src, u_char dst, short s
 	/*splx(s);*/
 
 	/* wait for hsync */
-	mfp_wait_for_hsync ();
+	mfp_wait_for_hsync();
 
 	/* stop raster copy */
-	CRTC.crtctrl = 0;
+	CRTC.crtctrl = 0x0000;
 
 	CRTC.r21 = saved_r21;
 }
@@ -142,13 +141,13 @@ txrascpy(u_char src, u_char dst, short s
 void
 ite_set_glyph(void)
 {
-	u_char glyph = IODEVbase->io_sram[0x59];
+	uint8_t glyph = IODEVbase->io_sram[0x59];
 	
-	if (glyph & 4)
+	if ((glyph & 4) != 0)
 		SETGLYPH(0x82, '|');
-	if (glyph & 2)
+	if ((glyph & 2) != 0)
 		SETGLYPH(0x81, '~');
-	if (glyph & 1)
+	if ((glyph & 1) != 0)
 		SETGLYPH(0x80, '\\');
 }
 
@@ -165,7 +164,8 @@ tv_init(struct ite_softc *ip)
 	 */
 	tv_top = 0;
 	for (i = 0; i < PLANELINES; i++)
-		tv_row[i] = (void *)__UNVOLATILE(&IODEVbase->tvram[ROWOFFSET(i)]);
+		tv_row[i] =
+		    (void *)__UNVOLATILE(&IODEVbase->tvram[ROWOFFSET(i)]);
 	/* shadow ANK font */
 	memcpy(kern_font, (void *)&IODEVbase->cgrom0_8x16, 256 * FONTHEIGHT);
 	ite_set_glyph();
@@ -212,9 +212,11 @@ tv_init(struct ite_softc *ip)
 void
 tv_deinit(struct ite_softc *ip)
 {
+
 	ip->flags &= ~ITE_INITED; /* XXX? */
 }
 
+static inline uint8_t *tv_getfont(int, int);
 typedef void tv_putcfunc(struct ite_softc *, int, char *);
 static tv_putcfunc tv_putc_nm;
 static tv_putcfunc tv_putc_in;
@@ -226,32 +228,32 @@ static tv_putcfunc tv_putc_bd_ul;
 static tv_putcfunc tv_putc_bd_ul_in;
 
 static tv_putcfunc *putc_func[ATTR_ALL + 1] = {
-	tv_putc_nm,
-	tv_putc_in,
-	tv_putc_ul,
-	tv_putc_ul_in,
-	tv_putc_bd,
-	tv_putc_bd_in,
-	tv_putc_bd_ul,
-	tv_putc_bd_ul_in,
+	[ATTR_NOR]					= tv_putc_nm,
+	[ATTR_INV]					= tv_putc_in,
+	[ATTR_UL]					= tv_putc_ul,
+	[ATTR_INV | ATTR_UL]				= tv_putc_ul_in,
+	[ATTR_BOLD]					= tv_putc_bd,
+	[ATTR_BOLD | ATTR_INV]				= tv_putc_bd_in,
+	[ATTR_BOLD | ATTR_UL]				= tv_putc_bd_ul,
+	[ATTR_BOLD | ATTR_UL | ATTR_INV]		= tv_putc_bd_ul_in,
 	/* no support for blink */
-	tv_putc_nm,
-	tv_putc_in,
-	tv_putc_ul,
-	tv_putc_ul_in,
-	tv_putc_bd,
-	tv_putc_bd_in,
-	tv_putc_bd_ul,
-	tv_putc_bd_ul_in,
+	[ATTR_BLINK]					= tv_putc_nm,
+	[ATTR_BLINK | ATTR_INV]				= tv_putc_in,
+	[ATTR_BLINK | ATTR_UL]				= tv_putc_ul,
+	[ATTR_BLINK | ATTR_UL | ATTR_INV]		= tv_putc_ul_in,
+	[ATTR_BLINK | ATTR_BOLD]			= tv_putc_bd,
+	[ATTR_BLINK | ATTR_BOLD | ATTR_INV]		= tv_putc_bd_in,
+	[ATTR_BLINK | ATTR_BOLD | ATTR_UL]		= tv_putc_bd_ul,
+	[ATTR_BLINK | ATTR_BOLD | ATTR_UL | ATTR_INV]	= tv_putc_bd_ul_in,
 };
 
 /*
  * simple put character function
  */
-void
+static void
 tv_putc(struct ite_softc *ip, int ch, int y, int x, int mode)
 {
-	char *p = CHADDR(y, x);
+	uint8_t *p = CHADDR(y, x);
 	short fh;
 
 	/* multi page write mode */
@@ -264,7 +266,7 @@ tv_putc(struct ite_softc *ip, int ch, in
 	CRTC.r21 ^= 0x00f0;
 	if (ip->save_char) {
 		for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES)
-			*(u_short *)p = 0;
+			*(uint16_t *)p = 0;
 	} else {
 		for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES)
 			*p = 0;
@@ -274,138 +276,152 @@ tv_putc(struct ite_softc *ip, int ch, in
 	CRTC.r21 = 0;
 }
 
-void
+static inline uint8_t *
+tv_getfont(int cset, int ch)
+{
+
+	if (cset == CSET_JISKANA) {
+		ch |= 0x80;
+	} else if (cset == CSET_DECGRAPH) {
+		if (ch < 0x80) {
+			ch = ite_decgraph2ascii[ch];
+		}
+	}
+
+	return tv_font[ch];
+}
+
+static void
 tv_putc_nm(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES)
-			*(u_short *)p = *kf++;
+			*(uint16_t *)p = *kf++;
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES)
 		*p = *f++;
 }
 
-void
+static void
 tv_putc_in(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES)
-			*(u_short *)p = ~*kf++;
+			*(uint16_t *)p = ~*kf++;
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES)
 		*p = ~*f++;
 }
 
-void
+static void
 tv_putc_bd(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	u_int data;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-			ch = *kf++;
-			*(u_short *)p = ch | (ch >> 1);
+			data = *kf++;
+			*(uint16_t *)p = data | (data >> 1);
 		}
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-		ch = *f++;
-		*p = ch | (ch >> 1);
+		data = *f++;
+		*p = data | (data >> 1);
 	}
 }
 
-inline static int
-expbits(int data)
+static inline uint32_t
+expbits(uint32_t data)
 {
-	int i, nd = 0;
-	if (data & 1)
+	int i;
+	u_int nd = 0;
+
+	if ((data & 1) != 0)
 		nd |= 0x02;
-	for (i=1; i < 32; i++) {
-		if (data & (1 << i))
-			nd |= 0x5 << (i-1);
+	for (i = 1; i < 32; i++) {
+		if ((data & (1 << i)) != 0)
+			nd |= 0x5 << (i - 1);
 	}
 	nd &= ~data;
-	return (~nd);
+	return ~nd;
 }
 
-void
+static void
 tv_putc_ul(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES)
-			*(u_short *)p = *kf++;
-		*(u_short *)p = expbits(*kf++);
+			*(uint16_t *)p = *kf++;
+		*(uint16_t *)p = expbits(*kf++);
 		p += ROWBYTES;
 		for (fh++; fh < FONTHEIGHT; fh++, p += ROWBYTES)
-			*(u_short *)p = *kf++;
+			*(uint16_t *)p = *kf++;
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES)
@@ -416,66 +432,65 @@ tv_putc_ul(struct ite_softc *ip, int ch,
 		*p = *f++;
 }
 
-void
+static void
 tv_putc_bd_in(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	u_int data;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-			ch = *kf++;
-			*(u_short *)p = ~(ch | (ch >> 1));
+			data = *kf++;
+			*(uint16_t *)p = ~(data | (data >> 1));
 		}
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-		ch = *f++;
-		*p = ~(ch | (ch >> 1));
+		data = *f++;
+		*p = ~(data | (data >> 1));
 	}
 }
 
-void
+static void
 tv_putc_ul_in(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES)
-			*(u_short *)p = ~*kf++;
-		*(u_short *)p = ~expbits(*kf++);
+			*(uint16_t *)p = ~*kf++;
+		*(uint16_t *)p = ~expbits(*kf++);
 		p += ROWBYTES;
 		for (fh++; fh < FONTHEIGHT; fh++, p += ROWBYTES)
-			*(u_short *)p = ~*kf++;
+			*(uint16_t *)p = ~*kf++;
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES)
@@ -486,108 +501,108 @@ tv_putc_ul_in(struct ite_softc *ip, int 
 		*p = ~*f++;
 }
 
-void
+static void
 tv_putc_bd_ul(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	u_int data;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES) {
-			ch = *kf++;
-			*(u_short *)p = ch | (ch >> 1);
+			data = *kf++;
+			*(uint16_t *)p = data | (data >> 1);
 		}
-		ch = *kf++;
-		*(u_short *)p = expbits(ch | (ch >> 1));
+		data = *kf++;
+		*(uint16_t *)p = expbits(data | (data >> 1));
 		p += ROWBYTES;
 		for (fh++; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-			ch = *kf++;
-			*(u_short *)p = ch | (ch >> 1);
+			data = *kf++;
+			*(uint16_t *)p = data | (data >> 1);
 		}
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES) {
-		ch = *f++;
-		*p = ch | (ch >> 1);
+		data = *f++;
+		*p = data | (data >> 1);
 	}
-	ch = *f++;
-	*p = expbits(ch | (ch >> 1));
+	data = *f++;
+	*p = expbits(data | (data >> 1));
 	p += ROWBYTES;
 	for (fh++; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-		ch = *f++;
-		*p = ch | (ch >> 1);
+		data = *f++;
+		*p = data | (data >> 1);
 	}
 }
 
-void
+static void
 tv_putc_bd_ul_in(struct ite_softc *ip, int ch, char *p)
 {
 	short fh, hi;
-	char *f;
-	volatile short *kf;
+	u_int data;
+	volatile uint16_t *kf;
+	uint8_t *f;
 
 	hi = ip->save_char & 0x7f;
 
-	if (hi >= 0x21 && hi <= 0x7e && ch >= 0x21 && ch <= 0x7e) {
+	if (hi >= 0x21 && hi <= 0x7e &&
+	    (ch & 0x7f) >= 0x21 && (ch & 0x7f) <= 0x7e) {
 		/* multibyte character */
-		kf = (volatile short *)tv_kfont[hi];
-		kf += ch * FONTHEIGHT;
+		kf = (volatile uint16_t *)tv_kfont[hi];
+		kf += (ch & 0x7f) * FONTHEIGHT;
 		/* draw plane */
 		for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES) {
-			ch = *kf++;
-			*(u_short *)p = ~(ch | (ch >> 1));
+			data = *kf++;
+			*(uint16_t *)p = ~(data | (data >> 1));
 		}
-		ch = *kf++;
-		*(u_short *)p = ~expbits(ch | (ch >> 1));
+		data = *kf++;
+		*(uint16_t *)p = ~expbits(data | (data >> 1));
 		p += ROWBYTES;
 		for (fh++; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-			ch = *kf++;
-			*(u_short *)p = ~(ch | (ch >> 1));
+			data = *kf++;
+			*(uint16_t *)p = ~(data | (data >> 1));
 		}
 		return;
 	}
 
 	/* singlebyte character */
-	if (*ip->GL == CSET_JISKANA)
-		ch |= 0x80;
-	f = tv_font[ch];
+	f = tv_getfont(*ip->GL, ch);
 
 	/* draw plane */
 	for (fh = 0; fh < UNDERLINE; fh++, p += ROWBYTES) {
-		ch = *f++;
-		*p = ~(ch | (ch >> 1));
+		data = *f++;
+		*p = ~(data | (data >> 1));
 	}
-	ch = *f++;
-	*p = ~expbits(ch | (ch >> 1));
+	data = *f++;
+	*p = ~expbits(data | (data >> 1));
 	p += ROWBYTES;
 	for (fh++; fh < FONTHEIGHT; fh++, p += ROWBYTES) {
-		ch = *f++;
-		ch |= ch >> 1;
-		*p = ~(ch | (ch >> 1));
+		data = *f++;
+		data |= data >> 1;
+		*p = ~(data | (data >> 1));
 	}
 }
 
 /*
  * draw/erase/move cursor
  */
-void
+static void
 tv_cursor(struct ite_softc *ip, int flag)
 {
-	u_char *p;
+	uint8_t *p;
 	short fh;
 
 	/* erase */
@@ -626,10 +641,10 @@ tv_cursor(struct ite_softc *ip, int flag
 /*
  * clear rectangle
  */
-void
+static void
 tv_clear(struct ite_softc *ip, int y, int x, int height, int width)
 {
-	char *p;
+	uint8_t *p;
 	short fh;
 
 	/* XXX: reset scroll register on clearing whole screen */
@@ -651,7 +666,7 @@ tv_clear(struct ite_softc *ip, int y, in
 /*
  * scroll lines/columns
  */
-void
+static void
 tv_scroll(struct ite_softc *ip, int srcy, int srcx, int count, int dir)
 {
 	int dst, siz, pl;
@@ -698,8 +713,8 @@ tv_scroll(struct ite_softc *ip, int srcy
 	case SCROLL_LEFT:
 		for (pl = 0; pl < PLANESIZE * 4; pl += PLANESIZE) {
 			short fh;
-			char *src = CHADDR(srcy, srcx) + pl;
-			char *dest = CHADDR(srcy, srcx - count) + pl;
+			uint8_t *src = CHADDR(srcy, srcx) + pl;
+			uint8_t *dest = CHADDR(srcy, srcx - count) + pl;
 
 			siz = ip->cols - srcx;
 			for (fh = 0; fh < FONTHEIGHT; fh++) {
@@ -713,8 +728,8 @@ tv_scroll(struct ite_softc *ip, int srcy
 	case SCROLL_RIGHT:
 		for (pl = 0; pl < PLANESIZE * 4; pl += PLANESIZE) {
 			short fh;
-			char *src = CHADDR(srcy, srcx) + pl;
-			char *dest = CHADDR(srcy, srcx + count) + pl;
+			uint8_t *src = CHADDR(srcy, srcx) + pl;
+			uint8_t *dest = CHADDR(srcy, srcx + count) + pl;
 
 			siz = ip->cols - (srcx + count);
 			for (fh = 0; fh < FONTHEIGHT; fh++) {

Index: src/sys/arch/x68k/dev/itevar.h
diff -u src/sys/arch/x68k/dev/itevar.h:1.15 src/sys/arch/x68k/dev/itevar.h:1.16
--- src/sys/arch/x68k/dev/itevar.h:1.15	Wed Oct 10 17:49:50 2012
+++ src/sys/arch/x68k/dev/itevar.h	Sat Jun 25 03:18:38 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: itevar.h,v 1.15 2012/10/10 17:49:50 tsutsui Exp $	*/
+/*	$NetBSD: itevar.h,v 1.16 2022/06/25 03:18:38 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -223,6 +223,7 @@ enum tab_size { TABSIZE = 8 };
 #define CSET_JIS1978	(3|CSET_MULTI) /* iso2022jp old jis kanji */
 #define CSET_JIS1983	(4|CSET_MULTI) /* iso2022jp new jis kanji */
 #define CSET_JIS1990	(5|CSET_MULTI) /* iso2022jp hojo kanji */
+#define CSET_DECGRAPH	6 /* DEC special graphics characters */
 
 struct consdev;
 
@@ -235,7 +236,6 @@ void	itecnfinish(struct ite_softc *);
 
 /* standard ite device entry points. */
 void	iteinit(dev_t);
-void	itestart(struct tty *);
 
 /* ite functions */
 int	iteon(dev_t, int);
@@ -256,4 +256,7 @@ extern unsigned char kern_font[];
 extern unsigned char kbdled;
 void ite_set_glyph(void);
 void kbd_setLED(void);
+
+/* DEC special graphics character to ASCII table for box drawing etc. */
+extern const uint8_t ite_decgraph2ascii[];
 #endif

Reply via email to