aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/syscons
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/syscons')
-rw-r--r--sys/dev/syscons/apm/apm_saver.c93
-rw-r--r--sys/dev/syscons/blank/blank_saver.c67
-rw-r--r--sys/dev/syscons/daemon/daemon_saver.c386
-rw-r--r--sys/dev/syscons/dragon/dragon_saver.c257
-rw-r--r--sys/dev/syscons/fade/fade_saver.c99
-rw-r--r--sys/dev/syscons/fire/fire_saver.c199
-rw-r--r--sys/dev/syscons/green/green_saver.c68
-rw-r--r--sys/dev/syscons/logo/logo.c358
-rw-r--r--sys/dev/syscons/logo/logo_saver.c174
-rw-r--r--sys/dev/syscons/rain/rain_saver.c181
-rw-r--r--sys/dev/syscons/scgfbrndr.c366
-rw-r--r--sys/dev/syscons/schistory.c326
-rw-r--r--sys/dev/syscons/scmouse.c906
-rw-r--r--sys/dev/syscons/scterm-teken.c520
-rw-r--r--sys/dev/syscons/scterm.c126
-rw-r--r--sys/dev/syscons/scvesactl.c147
-rw-r--r--sys/dev/syscons/scvgarndr.c1251
-rw-r--r--sys/dev/syscons/scvidctl.c884
-rw-r--r--sys/dev/syscons/scvtb.c324
-rw-r--r--sys/dev/syscons/snake/snake_saver.c133
-rw-r--r--sys/dev/syscons/star/star_saver.c128
-rw-r--r--sys/dev/syscons/syscons.c3675
-rw-r--r--sys/dev/syscons/syscons.h673
-rw-r--r--sys/dev/syscons/sysmouse.c249
-rw-r--r--sys/dev/syscons/teken/Makefile13
-rw-r--r--sys/dev/syscons/teken/gensequences157
-rw-r--r--sys/dev/syscons/teken/sequences109
-rw-r--r--sys/dev/syscons/teken/teken.c430
-rw-r--r--sys/dev/syscons/teken/teken.h181
-rw-r--r--sys/dev/syscons/teken/teken_demo.c367
-rw-r--r--sys/dev/syscons/teken/teken_scs.h98
-rw-r--r--sys/dev/syscons/teken/teken_stress.c123
-rw-r--r--sys/dev/syscons/teken/teken_subr.h1209
-rw-r--r--sys/dev/syscons/teken/teken_subr_compat.h77
-rw-r--r--sys/dev/syscons/teken/teken_wcwidth.h120
-rw-r--r--sys/dev/syscons/warp/warp_saver.c167
36 files changed, 14641 insertions, 0 deletions
diff --git a/sys/dev/syscons/apm/apm_saver.c b/sys/dev/syscons/apm/apm_saver.c
new file mode 100644
index 000000000000..567b452e0b2e
--- /dev/null
+++ b/sys/dev/syscons/apm/apm_saver.c
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 1999 Nick Sayer (who stole shamelessly from blank_saver)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/condvar.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#include <sys/selinfo.h>
+#include <machine/apm_bios.h>
+#include <machine/pc/bios.h>
+#include <machine/bus.h>
+#include <i386/bios/apm.h>
+
+extern int apm_display(int newstate);
+
+extern struct apm_softc apm_softc;
+
+static int blanked=0;
+
+static int
+apm_saver(video_adapter_t *adp, int blank)
+{
+ if (!apm_softc.initialized || !apm_softc.active)
+ return 0;
+
+ if (blank==blanked)
+ return 0;
+
+ blanked=blank;
+
+ apm_display(!blanked);
+
+ return 0;
+}
+
+static int
+apm_init(video_adapter_t *adp)
+{
+ if (!apm_softc.initialized || !apm_softc.active)
+ printf("WARNING: apm_saver module requires apm enabled\n");
+ return 0;
+}
+
+static int
+apm_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t apm_module = {
+ "apm_saver", apm_init, apm_term, apm_saver, NULL,
+};
+
+SAVER_MODULE(apm_saver, apm_module);
+MODULE_DEPEND(apm_saver, apm, 1, 1, 1);
diff --git a/sys/dev/syscons/blank/blank_saver.c b/sys/dev/syscons/blank/blank_saver.c
new file mode 100644
index 000000000000..ad1ef743abfc
--- /dev/null
+++ b/sys/dev/syscons/blank/blank_saver.c
@@ -0,0 +1,67 @@
+/*-
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+static int
+blank_saver(video_adapter_t *adp, int blank)
+{
+ vidd_blank_display(adp, (blank) ? V_DISPLAY_BLANK : V_DISPLAY_ON);
+ return 0;
+}
+
+static int
+blank_init(video_adapter_t *adp)
+{
+ if (vidd_blank_display(adp, V_DISPLAY_ON) == 0)
+ return 0;
+ return ENODEV;
+}
+
+static int
+blank_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t blank_module = {
+ "blank_saver", blank_init, blank_term, blank_saver, NULL,
+};
+
+SAVER_MODULE(blank_saver, blank_module);
diff --git a/sys/dev/syscons/daemon/daemon_saver.c b/sys/dev/syscons/daemon/daemon_saver.c
new file mode 100644
index 000000000000..7530b4d9f3b8
--- /dev/null
+++ b/sys/dev/syscons/daemon/daemon_saver.c
@@ -0,0 +1,386 @@
+/*-
+ * Copyright (c) 1997 Sandro Sigala, Brescia, Italy.
+ * Copyright (c) 1997 Chris Shenton
+ * Copyright (c) 1995 S ren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/malloc.h>
+#include <sys/jail.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <machine/pc/display.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define DAEMON_MAX_WIDTH 32
+#define DAEMON_MAX_HEIGHT 19
+
+static u_char *message;
+static int messagelen;
+static int blanked;
+static int attr_mask;
+
+#define ATTR(attr) (((attr) & attr_mask) << 8)
+
+/* Who is the author of this ASCII pic? */
+
+static u_char *daemon_pic[] = {
+ " , ,",
+ " /( )`",
+ " \\ \\___ / |",
+ " /- _ `-/ '",
+ " (/\\/ \\ \\ /\\",
+ " / / | ` \\",
+ " O O ) / |",
+ " `-^--'`< '",
+ " (_.) _ ) /",
+ " `.___/` /",
+ " `-----' /",
+ "<----. __ / __ \\",
+ "<----|====O)))==) \\) /====",
+ "<----' `--' `.__,' \\",
+ " | |",
+ " \\ / /\\",
+ " ______( (_ / \\______/",
+ " ,' ,-----' |",
+ " `--{__________)",
+ NULL
+};
+
+static u_char *daemon_attr[] = {
+ " R R",
+ " RR RR",
+ " R RRRR R R",
+ " RR W RRR R",
+ " RWWW W R RR",
+ " W W W R R",
+ " B B W R R",
+ " WWWWWWRR R",
+ " RRRR R R R",
+ " RRRRRRR R",
+ " RRRRRRR R",
+ "YYYYYY RR R RR R",
+ "YYYYYYYYYYRRRRYYR RR RYYYY",
+ "YYYYYY RRRR RRRRRR R",
+ " R R",
+ " R R RR",
+ " CCCCCCR RR R RRRRRRRR",
+ " CC CCCCCCC C",
+ " CCCCCCCCCCCCCCC",
+ NULL
+};
+
+/*
+ * Reverse a graphics character, or return unaltered if no mirror;
+ * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
+ */
+
+static u_char
+xflip_symbol(u_char symbol)
+{
+ static const u_char lchars[] = "`'(){}[]\\/<>";
+ static const u_char rchars[] = "'`)(}{][/\\><";
+ int pos;
+
+ for (pos = 0; lchars[pos] != '\0'; pos++)
+ if (lchars[pos] == symbol)
+ return rchars[pos];
+
+ return symbol;
+}
+
+static void
+clear_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
+ int xlen, int ylen)
+{
+ int y;
+
+ if (xlen <= 0)
+ return;
+ for (y = yoff; y < ylen; y++) {
+ sc_vtb_erase(&sc->cur_scp->scr,
+ (ypos + y)*sc->cur_scp->xsize + xpos + xoff,
+ xlen - xoff,
+ sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
+ }
+}
+
+static void
+draw_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
+ int xlen, int ylen)
+{
+ int x, y;
+ int px;
+ int attr;
+
+ for (y = yoff; y < ylen; y++) {
+ if (dxdir < 0)
+ px = xoff;
+ else
+ px = DAEMON_MAX_WIDTH - xlen;
+ if (px >= strlen(daemon_pic[y]))
+ continue;
+ for (x = xoff; (x < xlen) && (daemon_pic[y][px] != '\0'); x++, px++) {
+ switch (daemon_attr[y][px]) {
+ case 'R': attr = FG_LIGHTRED | BG_BLACK; break;
+ case 'Y': attr = FG_YELLOW | BG_BLACK; break;
+ case 'B': attr = FG_LIGHTBLUE | BG_BLACK; break;
+ case 'W': attr = FG_LIGHTGREY | BG_BLACK; break;
+ case 'C': attr = FG_CYAN | BG_BLACK; break;
+ default: attr = FG_WHITE | BG_BLACK; break;
+ }
+ if (dxdir < 0) { /* Moving left */
+ sc_vtb_putc(&sc->cur_scp->scr,
+ (ypos + y)*sc->cur_scp->xsize
+ + xpos + x,
+ sc->scr_map[daemon_pic[y][px]],
+ ATTR(attr));
+ } else { /* Moving right */
+ sc_vtb_putc(&sc->cur_scp->scr,
+ (ypos + y)*sc->cur_scp->xsize
+ + xpos + DAEMON_MAX_WIDTH
+ - px - 1,
+ sc->scr_map[xflip_symbol(daemon_pic[y][px])],
+ ATTR(attr));
+ }
+ }
+ }
+}
+
+static void
+clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
+{
+ if (len <= 0)
+ return;
+ sc_vtb_erase(&sc->cur_scp->scr,
+ ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff,
+ sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
+}
+
+static void
+draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, u_char *s, int len)
+{
+ int x;
+
+ for (x = xoff; x < len; x++)
+ sc_vtb_putc(&sc->cur_scp->scr,
+ ypos*sc->cur_scp->xsize + xpos + x,
+ sc->scr_map[s[x]], ATTR(FG_LIGHTGREEN | BG_BLACK));
+}
+
+static int
+daemon_saver(video_adapter_t *adp, int blank)
+{
+ static int txpos = 10, typos = 10;
+ static int txdir = -1, tydir = -1;
+ static int dxpos = 0, dypos = 0;
+ static int dxdir = 1, dydir = 1;
+ static int moved_daemon = 0;
+ static int xoff, yoff, toff;
+ static int xlen, ylen, tlen;
+ sc_softc_t *sc;
+ scr_stat *scp;
+ int min, max;
+
+ sc = sc_find_softc(adp, NULL);
+ if (sc == NULL)
+ return EAGAIN;
+ scp = sc->cur_scp;
+
+ if (blank) {
+ if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
+ return EAGAIN;
+ if (blanked == 0) {
+ /* clear the screen and set the border color */
+ sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
+ ATTR(FG_LIGHTGREY | BG_BLACK));
+ vidd_set_hw_cursor(adp, -1, -1);
+ sc_set_border(scp, 0);
+ xlen = ylen = tlen = 0;
+ }
+ if (blanked++ < 2)
+ return 0;
+ blanked = 1;
+
+ clear_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
+ clear_string(sc, txpos, typos, toff, message, tlen);
+
+ if (++moved_daemon) {
+ /*
+ * The daemon picture may be off the screen, if
+ * screen size is chagened while the screen
+ * saver is inactive. Make sure the origin of
+ * the picture is between min and max.
+ */
+ if (scp->xsize <= DAEMON_MAX_WIDTH) {
+ /*
+ * If the screen width is too narrow, we
+ * allow part of the picture go off
+ * the screen so that the daemon won't
+ * flip too often.
+ */
+ min = scp->xsize - DAEMON_MAX_WIDTH - 10;
+ max = 10;
+ } else {
+ min = 0;
+ max = scp->xsize - DAEMON_MAX_WIDTH;
+ }
+ if (dxpos <= min) {
+ dxpos = min;
+ dxdir = 1;
+ } else if (dxpos >= max) {
+ dxpos = max;
+ dxdir = -1;
+ }
+
+ if (scp->ysize <= DAEMON_MAX_HEIGHT) {
+ min = scp->ysize - DAEMON_MAX_HEIGHT - 10;
+ max = 10;
+ } else {
+ min = 0;
+ max = scp->ysize - DAEMON_MAX_HEIGHT;
+ }
+ if (dypos <= min) {
+ dypos = min;
+ dydir = 1;
+ } else if (dypos >= max) {
+ dypos = max;
+ dydir = -1;
+ }
+
+ moved_daemon = -1;
+ dxpos += dxdir; dypos += dydir;
+
+ /* clip the picture */
+ xoff = 0;
+ xlen = DAEMON_MAX_WIDTH;
+ if (dxpos + xlen <= 0)
+ xlen = 0;
+ else if (dxpos < 0)
+ xoff = -dxpos;
+ if (dxpos >= scp->xsize)
+ xlen = 0;
+ else if (dxpos + xlen > scp->xsize)
+ xlen = scp->xsize - dxpos;
+ yoff = 0;
+ ylen = DAEMON_MAX_HEIGHT;
+ if (dypos + ylen <= 0)
+ ylen = 0;
+ else if (dypos < 0)
+ yoff = -dypos;
+ if (dypos >= scp->ysize)
+ ylen = 0;
+ else if (dypos + ylen > scp->ysize)
+ ylen = scp->ysize - dypos;
+ }
+
+ if (scp->xsize <= messagelen) {
+ min = scp->xsize - messagelen - 10;
+ max = 10;
+ } else {
+ min = 0;
+ max = scp->xsize - messagelen;
+ }
+ if (txpos <= min) {
+ txpos = min;
+ txdir = 1;
+ } else if (txpos >= max) {
+ txpos = max;
+ txdir = -1;
+ }
+ if (typos <= 0) {
+ typos = 0;
+ tydir = 1;
+ } else if (typos >= scp->ysize - 1) {
+ typos = scp->ysize - 1;
+ tydir = -1;
+ }
+ txpos += txdir; typos += tydir;
+
+ toff = 0;
+ tlen = messagelen;
+ if (txpos + tlen <= 0)
+ tlen = 0;
+ else if (txpos < 0)
+ toff = -txpos;
+ if (txpos >= scp->xsize)
+ tlen = 0;
+ else if (txpos + tlen > scp->xsize)
+ tlen = scp->xsize - txpos;
+
+ draw_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
+ draw_string(sc, txpos, typos, toff, message, tlen);
+ } else
+ blanked = 0;
+
+ return 0;
+}
+
+static int
+daemon_init(video_adapter_t *adp)
+{
+
+ mtx_lock(&prison0.pr_mtx);
+ messagelen = strlen(prison0.pr_host) + 3 + strlen(ostype) + 1 +
+ strlen(osrelease);
+ message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
+ sprintf(message, "%s - %s %s", prison0.pr_host, ostype, osrelease);
+ mtx_unlock(&prison0.pr_mtx);
+ blanked = 0;
+ switch (adp->va_mode) {
+ case M_PC98_80x25:
+ case M_PC98_80x30:
+ attr_mask = ~FG_UNDERLINE;
+ break;
+ default:
+ attr_mask = ~0;
+ break;
+ }
+
+ return 0;
+}
+
+static int
+daemon_term(video_adapter_t *adp)
+{
+ free(message, M_DEVBUF);
+ return 0;
+}
+
+static scrn_saver_t daemon_module = {
+ "daemon_saver", daemon_init, daemon_term, daemon_saver, NULL,
+};
+
+SAVER_MODULE(daemon_saver, daemon_module);
diff --git a/sys/dev/syscons/dragon/dragon_saver.c b/sys/dev/syscons/dragon/dragon_saver.c
new file mode 100644
index 000000000000..6294daa77615
--- /dev/null
+++ b/sys/dev/syscons/dragon/dragon_saver.c
@@ -0,0 +1,257 @@
+/*-
+ * Copyright (c) 2000 Chiharu Shibata
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/syslog.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <sys/random.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define SAVER_NAME "dragon_saver"
+
+static u_char *vid;
+static int blanked;
+
+#ifdef PC98
+#define VIDEO_MODE M_PC98_EGC640x400
+#define VIDEO_MODE_NAME "M_PC98_EGC640x400"
+#define SCRW 640
+#define SCRH 400
+#else
+#define VIDEO_MODE M_VGA_CG320
+#define VIDEO_MODE_NAME "M_VGA_CG320"
+#define SCRW 320
+#define SCRH 200
+#endif
+#define ORDER 13
+#define CURVE 3
+#define OUT 100
+
+static int cur_x, cur_y;
+static int curve;
+static u_char dragon_pal[3*256]; /* zero-filled by the compiler */
+
+static __inline int
+gpset(int x, int y, int val)
+{
+ if (x < 0 || y < 0 || SCRW <= x || SCRH <= y) {
+ return 0;
+ }
+#ifdef PC98
+ vid[(x + y * SCRW) >> 3] = (0x80 >> (x & 7)); /* write new dot */
+#else
+ vid[x + y * SCRW] = val;
+#endif
+ return 1;
+}
+
+static int
+gdraw(int dx, int dy, int val)
+{
+ int i;
+ int set = 0;
+
+#ifdef PC98
+ outb(0x7c, 0xcc); /* GRCG on & RMW mode(disable planeI,G) */
+ outb(0x7e, (val & 1) ? 0xff: 0); /* tile B */
+ outb(0x7e, (val & 2) ? 0xff: 0); /* tile R */
+#endif
+ if (dx != 0) {
+ i = cur_x;
+ cur_x += dx;
+ if (dx < 0) {
+ i += dx;
+ dx = -dx;
+ }
+ /* horizontal line */
+ for (; dx >= 0; --dx, ++i) {
+ set |= gpset(i, cur_y, val);
+ }
+ }
+ else { /* dy != 0 */
+ i = cur_y;
+ cur_y += dy;
+ if (dy < 0) {
+ i += dy;
+ dy = -dy;
+ }
+ /* vertical line */
+ for (; dy >= 0; --dy, ++i) {
+ set |= gpset(cur_x, i, val);
+ }
+ }
+#ifdef PC98
+ outb(0x7c, 0); /* GRCG off */
+#endif
+ return set;
+}
+
+static void
+dragon_update(video_adapter_t *adp)
+{
+ static int i, p, q;
+ static int order, mul, out;
+ static int org_x, org_y;
+ static int dx, dy;
+ static unsigned char fold[1 << (ORDER - 3)];
+#define GET_FOLD(x) (fold[(x) >> 3] & (1 << ((x) & 7)))
+#define SET_FOLD(x) (fold[(x) >> 3] |= (1 << ((x) & 7)))
+#define CLR_FOLD(x) (fold[(x) >> 3] &= ~(1 << ((x) & 7)))
+ int tmp;
+
+ if (curve > CURVE) {
+ vidd_clear(adp);
+
+ /* set palette of each curves */
+ for (tmp = 0; tmp < 3*CURVE; ++tmp) {
+ dragon_pal[3+tmp] = (u_char)random();
+ }
+ vidd_load_palette(adp, dragon_pal);
+
+ mul = ((random() & 7) + 1) * (SCRW / 320);
+ org_x = random() % SCRW; org_y = random() % SCRH;
+
+ curve = 0;
+ order = ORDER;
+ }
+
+ if (order >= ORDER) {
+ ++curve;
+
+ cur_x = org_x; cur_y = org_y;
+
+ switch (curve) {
+ case 1:
+ dx = 0; dy = mul;
+ break;
+ case 2:
+ dx = mul; dy = 0;
+ break;
+ case 3:
+ dx = 0; dy = -mul;
+ break;
+ }
+ (void)gdraw(dx, dy, curve); out = 0;
+
+ order = 0;
+ q = p = 0; i = q + 1;
+ }
+
+ if (i > q) {
+ SET_FOLD(p); q = p * 2;
+
+ ++order;
+ i = p; p = q + 1;
+ }
+
+ if (GET_FOLD(q-i) != 0) {
+ CLR_FOLD(i);
+ tmp = dx; dx = dy; dy = -tmp; /* turn right */
+ }
+ else {
+ SET_FOLD(i);
+ tmp = dx; dx = -dy; dy = tmp; /* turn left */
+ }
+ if (gdraw(dx, dy, curve)) {
+ out = 0;
+ }
+ else {
+ if (++out > OUT) {
+ order = ORDER; /* force to terminate this curve */
+ }
+ }
+ ++i;
+}
+
+static int
+dragon_saver(video_adapter_t *adp, int blank)
+{
+ int pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ vidd_set_mode(adp, VIDEO_MODE);
+ vid = (u_char *)adp->va_window;
+ curve = CURVE + 1;
+ ++blanked;
+ splx(pl);
+ }
+
+ /* update display */
+ dragon_update(adp);
+ }
+ else {
+ blanked = 0;
+ }
+ return 0;
+}
+
+static int
+dragon_init(video_adapter_t *adp)
+{
+ video_info_t info;
+
+ /* check that the console is capable of running in 320x200x256 */
+ if (vidd_get_info(adp, VIDEO_MODE, &info)) {
+ log(LOG_NOTICE,
+ "%s: the console does not support " VIDEO_MODE_NAME "\n",
+ SAVER_NAME);
+ return ENODEV;
+ }
+
+ blanked = 0;
+ return 0;
+}
+
+static int
+dragon_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t dragon_module = {
+ SAVER_NAME,
+ dragon_init,
+ dragon_term,
+ dragon_saver,
+ NULL,
+};
+
+SAVER_MODULE(dragon_saver, dragon_module);
diff --git a/sys/dev/syscons/fade/fade_saver.c b/sys/dev/syscons/fade/fade_saver.c
new file mode 100644
index 000000000000..27d732c084d9
--- /dev/null
+++ b/sys/dev/syscons/fade/fade_saver.c
@@ -0,0 +1,99 @@
+/*-
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+static u_char palette[256*3];
+
+static int
+fade_saver(video_adapter_t *adp, int blank)
+{
+ static int count = 0;
+ u_char pal[256*3];
+ int i;
+
+ if (blank) {
+ if (ISPALAVAIL(adp->va_flags)) {
+ if (count <= 0)
+ vidd_save_palette(adp, palette);
+ if (count < 256) {
+ pal[0] = pal[1] = pal[2] = 0;
+ for (i = 3; i < 256*3; i++) {
+ if (palette[i] - count > 60)
+ pal[i] = palette[i] - count;
+ else
+ pal[i] = 60;
+ }
+ vidd_load_palette(adp, pal);
+ count++;
+ }
+ } else {
+ vidd_blank_display(adp, V_DISPLAY_BLANK);
+ }
+ } else {
+ if (ISPALAVAIL(adp->va_flags)) {
+ vidd_load_palette(adp, palette);
+ count = 0;
+ } else {
+ vidd_blank_display(adp, V_DISPLAY_ON);
+ }
+ }
+ return 0;
+}
+
+static int
+fade_init(video_adapter_t *adp)
+{
+ if (!ISPALAVAIL(adp->va_flags) &&
+ vidd_blank_display(adp, V_DISPLAY_ON) != 0)
+ return ENODEV;
+ return 0;
+}
+
+static int
+fade_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t fade_module = {
+ "fade_saver", fade_init, fade_term, fade_saver, NULL,
+};
+
+SAVER_MODULE(fade_saver, fade_module);
diff --git a/sys/dev/syscons/fire/fire_saver.c b/sys/dev/syscons/fire/fire_saver.c
new file mode 100644
index 000000000000..4c995efcd640
--- /dev/null
+++ b/sys/dev/syscons/fire/fire_saver.c
@@ -0,0 +1,199 @@
+/*-
+ * Copyright (c) 1999 Brad Forschinger
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * brad forschinger, 19990504 <retch@flag.blackened.net>
+ *
+ * written with much help from warp_saver.c
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/syslog.h>
+#include <sys/consio.h>
+#include <sys/malloc.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define SAVER_NAME "fire_saver"
+
+#define RED(n) ((n) * 3 + 0)
+#define GREEN(n) ((n) * 3 + 1)
+#define BLUE(n) ((n) * 3 + 2)
+
+#define SET_ORIGIN(adp, o) do { \
+ int oo = o; \
+ if (oo != last_origin) \
+ vidd_set_win_org(adp, last_origin = oo); \
+ } while (0)
+
+static u_char *buf;
+static u_char *vid;
+static int banksize, scrmode, bpsl, scrw, scrh;
+static u_char fire_pal[768];
+static int blanked;
+
+static void
+fire_update(video_adapter_t *adp)
+{
+ int x, y;
+ int o, p;
+ int last_origin = -1;
+
+ /* make a new bottom line */
+ for (x = 0, y = scrh; x < scrw; x++)
+ buf[x + (y * bpsl)] = random() % 160 + 96;
+
+ /* fade the flames out */
+ for (y = 0; y < scrh; y++) {
+ for (x = 0; x < scrw; x++) {
+ buf[x + (y * scrw)] =
+ (buf[(x + 0) + ((y + 0) * scrw)] +
+ buf[(x - 1) + ((y + 1) * scrw)] +
+ buf[(x + 0) + ((y + 1) * scrw)] +
+ buf[(x + 1) + ((y + 1) * scrw)]) / 4;
+ if (buf[x + (y * scrw)] > 0)
+ buf[x + (y * scrw)]--;
+ }
+ }
+
+ /* blit our buffer into video ram */
+ for (y = 0, p = 0, o = 0; y < scrh; y++, p += bpsl) {
+ while (p > banksize) {
+ p -= banksize;
+ o += banksize;
+ }
+ SET_ORIGIN(adp, o);
+ if (p + scrw < banksize) {
+ bcopy(buf + y * scrw, vid + p, scrw);
+ } else {
+ bcopy(buf + y * scrw, vid + p, banksize - p);
+ SET_ORIGIN(adp, o + banksize);
+ bcopy(buf + y * scrw + (banksize - p), vid,
+ scrw - (banksize - p));
+ p -= banksize;
+ o += banksize;
+ }
+ }
+
+}
+
+static int
+fire_saver(video_adapter_t *adp, int blank)
+{
+ int pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ vidd_set_mode(adp, scrmode);
+ vidd_load_palette(adp, fire_pal);
+ blanked++;
+ vid = (u_char *)adp->va_window;
+ banksize = adp->va_window_size;
+ bpsl = adp->va_line_width;
+ splx(pl);
+ vidd_clear(adp);
+ }
+ fire_update(adp);
+ } else {
+ blanked = 0;
+ }
+
+ return 0;
+}
+
+static int
+fire_init(video_adapter_t *adp)
+{
+ video_info_t info;
+ int i, red, green, blue;
+
+ if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
+ scrmode = M_VGA_CG320;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
+ scrmode = M_PC98_PEGC640x480;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
+ scrmode = M_PC98_PEGC640x400;
+ } else {
+ log(LOG_NOTICE,
+ "%s: the console does not support M_VGA_CG320\n",
+ SAVER_NAME);
+ return (ENODEV);
+ }
+
+ scrw = info.vi_width;
+ scrh = info.vi_height;
+
+ buf = (u_char *)malloc(scrw * (scrh + 1), M_DEVBUF, M_NOWAIT);
+ if (buf) {
+ bzero(buf, scrw * (scrh + 1));
+ } else {
+ log(LOG_NOTICE,
+ "%s: buffer allocation is failed\n",
+ SAVER_NAME);
+ return (ENODEV);
+ }
+
+ /* intialize the palette */
+ red = green = blue = 0;
+ for (i = 0; i < 256; i++) {
+ red++;
+ if (red > 128)
+ green += 2;
+ fire_pal[RED(i)] = red;
+ fire_pal[GREEN(i)] = green;
+ fire_pal[BLUE(i)] = blue;
+ }
+
+ return (0);
+}
+
+static int
+fire_term(video_adapter_t *adp)
+{
+ free(buf, M_DEVBUF);
+ return (0);
+}
+
+static scrn_saver_t fire_module = {
+ SAVER_NAME,
+ fire_init,
+ fire_term,
+ fire_saver,
+ NULL
+};
+
+SAVER_MODULE(fire_saver, fire_module);
diff --git a/sys/dev/syscons/green/green_saver.c b/sys/dev/syscons/green/green_saver.c
new file mode 100644
index 000000000000..b03cc7280119
--- /dev/null
+++ b/sys/dev/syscons/green/green_saver.c
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+static int
+green_saver(video_adapter_t *adp, int blank)
+{
+ vidd_blank_display(adp,
+ (blank) ? V_DISPLAY_STAND_BY : V_DISPLAY_ON);
+ return 0;
+}
+
+static int
+green_init(video_adapter_t *adp)
+{
+ if (vidd_blank_display(adp, V_DISPLAY_ON) == 0)
+ return 0;
+ return ENODEV;
+}
+
+static int
+green_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t green_module = {
+ "green_saver", green_init, green_term, green_saver, NULL,
+};
+
+SAVER_MODULE(green_saver, green_module);
diff --git a/sys/dev/syscons/logo/logo.c b/sys/dev/syscons/logo/logo.c
new file mode 100644
index 000000000000..ea3f46e5c3a7
--- /dev/null
+++ b/sys/dev/syscons/logo/logo.c
@@ -0,0 +1,358 @@
+/* $FreeBSD$ */
+
+#define logo_width 88
+#define logo_height 88
+
+unsigned int logo_w = logo_width;
+unsigned int logo_h = logo_height;
+
+unsigned char logo_pal[768] = {
+ 0x00, 0x00, 0x00,
+ 0x33, 0x33, 0x33,
+ 0x66, 0x66, 0x66,
+ 0x99, 0x99, 0x99,
+ 0xcc, 0xcc, 0xcc,
+ 0xff, 0xff, 0xff,
+ 0x90, 0x8f, 0x90,
+ 0x56, 0x4b, 0x55,
+ 0xa3, 0xa5, 0xab,
+ 0xfd, 0xfd, 0xfd,
+ 0x6d, 0x6e, 0x74,
+ 0x41, 0x2b, 0x39,
+ 0xcb, 0xc8, 0xcb,
+ 0xcf, 0xbb, 0xba,
+ 0x8e, 0x82, 0x87,
+ 0x5c, 0x5d, 0x60,
+ 0x52, 0x2a, 0x37,
+ 0x7f, 0x76, 0x7d,
+ 0x82, 0x82, 0x85,
+ 0x7a, 0x3e, 0x45,
+ 0x7f, 0x6e, 0x70,
+ 0xef, 0xef, 0xed,
+ 0x53, 0x41, 0x4b,
+ 0x67, 0x2b, 0x35,
+ 0x6a, 0x55, 0x62,
+ 0xe7, 0xe2, 0xe3,
+ 0x64, 0x35, 0x3f,
+ 0xf7, 0xe0, 0xe7,
+ 0xb1, 0xb2, 0xb2,
+ 0x31, 0x2b, 0x35,
+ 0x7a, 0x2d, 0x37,
+ 0x69, 0x4c, 0x56,
+ 0x95, 0x9d, 0xa4,
+ 0x85, 0x61, 0x69,
+ 0x40, 0x34, 0x41,
+ 0x8f, 0x2e, 0x39,
+ 0x7a, 0x50, 0x5a,
+ 0xde, 0xe1, 0xe0,
+ 0x32, 0x33, 0x3d,
+ 0xa0, 0x9b, 0x9c,
+ 0x68, 0x63, 0x67,
+ 0x76, 0x60, 0x67,
+ 0xba, 0xb6, 0xb8,
+ 0x29, 0x24, 0x41,
+ 0x38, 0x21, 0x29,
+ 0x42, 0x21, 0x27,
+ 0xa2, 0x2a, 0x32,
+ 0x56, 0x55, 0x58,
+ 0x55, 0x21, 0x2b,
+ 0x7a, 0x20, 0x2a,
+ 0x37, 0x16, 0x21,
+ 0x4d, 0x18, 0x37,
+ 0x8a, 0x3a, 0x3e,
+ 0xc0, 0xc2, 0xc4,
+ 0x64, 0x23, 0x2c,
+ 0x37, 0x1a, 0x24,
+ 0x42, 0x18, 0x20,
+ 0x4c, 0x21, 0x2b,
+ 0xa0, 0x23, 0x2e,
+ 0x95, 0x6c, 0x76,
+ 0x26, 0x16, 0x1c,
+ 0xa5, 0x18, 0x23,
+ 0x84, 0x20, 0x2b,
+ 0x6d, 0x3f, 0x49,
+ 0xae, 0xa7, 0xac,
+ 0x2a, 0x1f, 0x24,
+ 0x90, 0x21, 0x30,
+ 0xa0, 0x39, 0x3e,
+ 0x95, 0x0f, 0x1c,
+ 0x84, 0x13, 0x1e,
+ 0x4e, 0x17, 0x24,
+ 0x8c, 0x56, 0x5f,
+ 0xe0, 0xc4, 0xcb,
+ 0xa5, 0x7f, 0x8e,
+ 0xff, 0xff, 0xf1,
+ 0x3d, 0x3d, 0x5d,
+ 0x61, 0x19, 0x26,
+ 0xd5, 0xd5, 0xd5,
+ 0xff, 0xf1, 0xed,
+ 0xb6, 0x9c, 0xa5,
+ 0x87, 0x4c, 0x5a,
+ 0xa0, 0x76, 0x76,
+ 0xc8, 0xa0, 0xa0,
+ 0xa2, 0xc1, 0xc8,
+ 0x91, 0xae, 0xb6,
+ 0x52, 0x8b, 0xae,
+ 0xb3, 0xd2, 0xd4,
+ 0x95, 0xb7, 0xc1,
+ 0x54, 0x6e, 0x83,
+ 0x67, 0x90, 0xa6,
+ 0x44, 0x3e, 0x45,
+ 0x23, 0x40, 0x6a,
+ 0x41, 0x6e, 0x97,
+ 0x7e, 0x8e, 0x91,
+ 0x52, 0x33, 0x41,
+ 0x39, 0x49, 0x68,
+ 0x1d, 0x2a, 0x48,
+ 0x17, 0x21, 0x45,
+ 0x90, 0x17, 0x1f,
+ 0x38, 0x54, 0x71,
+ 0x1c, 0x33, 0x58,
+ 0x1c, 0x1e, 0x23,
+ 0x6c, 0x17, 0x21,
+ 0xb0, 0xc5, 0xc1,
+ 0x5d, 0x7f, 0x96,
+ 0xe9, 0xbf, 0xc1,
+ 0x96, 0x06, 0x0f,
+ 0x78, 0x16, 0x1e,
+ 0xab, 0x0e, 0x18,
+ 0xa6, 0x06, 0x0e,
+ 0x4c, 0x4c, 0x54,
+ 0x61, 0x42, 0x4c,
+ 0x48, 0x5f, 0x84,
+ 0xa0, 0xb8, 0xbe,
+ 0x5c, 0x66, 0x7f,
+ 0x7b, 0x9e, 0xa9,
+ 0x6f, 0x75, 0x7f,
+ 0x45, 0x54, 0x74,
+ 0x32, 0x3e, 0x63,
+ 0xb1, 0xb4, 0xb3,
+ 0x66, 0x9d, 0xb4,
+ 0x7a, 0x9f, 0xbb,
+ 0x82, 0xaa, 0xba,
+ 0x13, 0x15, 0x17,
+ 0x0b, 0x0b, 0x0a,
+ 0x37, 0x66, 0x92,
+ 0x4c, 0x7f, 0xa5,
+ 0x24, 0x4c, 0x7b,
+ 0x25, 0x5f, 0x91,
+ 0x40, 0x7d, 0xa5,
+ 0x1d, 0x56, 0x88,
+ 0x2d, 0x6f, 0xa0,
+ 0x70, 0x81, 0x8f,
+ 0x58, 0x97, 0xbd,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+};
+
+unsigned char logo_img[logo_width*logo_height] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x09, 0x0a, 0x0b, 0x07, 0x0c, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0d, 0x0e, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x05, 0x05, 0x05, 0x05, 0x09, 0x0f, 0x0b, 0x10, 0x11, 0x09, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x12, 0x13, 0x14, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x15, 0x16, 0x0b, 0x17, 0x18, 0x19, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11, 0x13, 0x1a, 0x1b, 0x05, 0x05, 0x05, 0x04, 0x03, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x1c, 0x1d, 0x10, 0x1e, 0x1f, 0x19, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x20, 0x0b, 0x1e, 0x21, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x19, 0x22, 0x0b, 0x17, 0x23, 0x24, 0x15, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x25, 0x26, 0x10, 0x23, 0x27, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x05, 0x05, 0x05, 0x25, 0x27, 0x11, 0x28, 0x29, 0x11, 0x06, 0x0d, 0x09, 0x05, 0x2a, 0x2b, 0x2c, 0x2d, 0x1e, 0x2e, 0x21, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x2f, 0x0b, 0x30, 0x31, 0x0c, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x15, 0x06, 0x16, 0x22, 0x1d, 0x2c, 0x32, 0x33, 0x17, 0x17, 0x17, 0x22, 0x14, 0x16, 0x1d, 0x2c, 0x2d, 0x1e, 0x2e, 0x34, 0x0c, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x35, 0x2b, 0x2c, 0x36, 0x36, 0x35, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x27, 0x0b, 0x2c, 0x2c, 0x37, 0x32, 0x38, 0x2c, 0x2d, 0x39, 0x36, 0x17, 0x30, 0x2c, 0x2c, 0x2d, 0x2c, 0x2c, 0x1a, 0x3a, 0x3a, 0x3b, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0a, 0x2d, 0x2b, 0x33, 0x31, 0x0e, 0x05, 0x05, 0x05, 0x05, 0x09, 0x28, 0x2c, 0x37, 0x3c, 0x32, 0x38, 0x38, 0x37, 0x2c, 0x30, 0x36, 0x36, 0x17, 0x31, 0x36, 0x23, 0x23, 0x17, 0x2c, 0x17, 0x3a, 0x3d, 0x13, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x22, 0x2c, 0x37, 0x33, 0x3e, 0x31, 0x3f, 0x40, 0x19, 0x05, 0x11, 0x2c, 0x2c, 0x32, 0x32, 0x32, 0x38, 0x37, 0x41, 0x30, 0x3a, 0x3a, 0x2e, 0x42, 0x43, 0x17, 0x1a, 0x13, 0x23, 0x31, 0x1a, 0x2e, 0x3d, 0x1a, 0x09, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0b, 0x37, 0x32, 0x37, 0x33, 0x44, 0x44, 0x45, 0x17, 0x1a, 0x10, 0x2d, 0x37, 0x38, 0x46, 0x33, 0x46, 0x32, 0x2c, 0x23, 0x23, 0x47, 0x21, 0x13, 0x43, 0x34, 0x48, 0x19, 0x49, 0x34, 0x17, 0x1e, 0x3a, 0x13, 0x4a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4b, 0x32, 0x32, 0x32, 0x32, 0x4c, 0x45, 0x44, 0x44, 0x42, 0x36, 0x30, 0x33, 0x46, 0x38, 0x33, 0x46, 0x38, 0x31, 0x23, 0x27, 0x09, 0x4a, 0x4d, 0x47, 0x43, 0x0d, 0x4e, 0x4a, 0x4f, 0x34, 0x1a, 0x2e, 0x29, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11, 0x33, 0x32, 0x32, 0x32, 0x33, 0x4c, 0x31, 0x45, 0x3e, 0x31, 0x36, 0x46, 0x46, 0x33, 0x33, 0x39, 0x30, 0x23, 0x50, 0x4a, 0x4a, 0x4a, 0x4a, 0x4d, 0x47, 0x51, 0x4e, 0x4a, 0x4a, 0x0e, 0x13, 0x1a, 0x27, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x35, 0x2b, 0x32, 0x32, 0x2b, 0x32, 0x33, 0x4c, 0x33, 0x4c, 0x4c, 0x36, 0x30, 0x30, 0x30, 0x30, 0x31, 0x23, 0x3a, 0x49, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4f, 0x50, 0x1b, 0x4e, 0x4a, 0x19, 0x50, 0x16, 0x0c, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x32, 0x32, 0x32, 0x32, 0x2b, 0x33, 0x33, 0x30, 0x2d, 0x39, 0x30, 0x30, 0x30, 0x4c, 0x36, 0x42, 0x3a, 0x52, 0x05, 0x4a, 0x4a, 0x4a, 0x4a, 0x09, 0x3b, 0x52, 0x4e, 0x4a, 0x4a, 0x4f, 0x1a, 0x2a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4d, 0x2b, 0x2b, 0x32, 0x32, 0x32, 0x37, 0x2c, 0x2c, 0x2c, 0x2c, 0x2d, 0x10, 0x30, 0x30, 0x3e, 0x23, 0x3a, 0x0d, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x40, 0x51, 0x4a, 0x4a, 0x25, 0x15, 0x1f, 0x27, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x40, 0x22, 0x2c, 0x32, 0x32, 0x32, 0x38, 0x2d, 0x2c, 0x41, 0x32, 0x39, 0x46, 0x4c, 0x31, 0x2e, 0x2e, 0x0c, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x25, 0x53, 0x18, 0x4a, 0x54, 0x55, 0x56, 0x51, 0x11, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x2a, 0x22, 0x32, 0x32, 0x32, 0x38, 0x38, 0x32, 0x2c, 0x37, 0x38, 0x30, 0x30, 0x3e, 0x3a, 0x3a, 0x2a, 0x4a, 0x4a, 0x05, 0x4a, 0x57, 0x58, 0x59, 0x5a, 0x35, 0x58, 0x5b, 0x5c, 0x5d, 0x5e, 0x4a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4d, 0x07, 0x37, 0x32, 0x38, 0x38, 0x32, 0x32, 0x41, 0x38, 0x30, 0x30, 0x3e, 0x3a, 0x3d, 0x27, 0x05, 0x4a, 0x4a, 0x4a, 0x5c, 0x5f, 0x59, 0x1d, 0x29, 0x2f, 0x60, 0x61, 0x26, 0x0b, 0x1c, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4e, 0x0a, 0x2d, 0x38, 0x38, 0x32, 0x37, 0x32, 0x2d, 0x39, 0x36, 0x31, 0x62, 0x3d, 0x0e, 0x4a, 0x4a, 0x4a, 0x09, 0x63, 0x64, 0x64, 0x61, 0x2d, 0x1d, 0x65, 0x61, 0x2b, 0x17, 0x16, 0x4a, 0x05, 0x05, 0x04, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x27, 0x2c, 0x38, 0x38, 0x37, 0x37, 0x38, 0x2d, 0x30, 0x31, 0x42, 0x3a, 0x18, 0x09, 0x05, 0x05, 0x4a, 0x63, 0x60, 0x60, 0x2b, 0x10, 0x2d, 0x41, 0x41, 0x30, 0x42, 0x3e, 0x29, 0x09, 0x05, 0x05, 0x04, 0x03, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x2a, 0x37, 0x32, 0x38, 0x32, 0x41, 0x38, 0x38, 0x30, 0x66, 0x31, 0x3a, 0x1e, 0x67, 0x4a, 0x4a, 0x05, 0x68, 0x64, 0x61, 0x2b, 0x17, 0x36, 0x10, 0x33, 0x31, 0x42, 0x3d, 0x45, 0x06, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x1c, 0x2c, 0x32, 0x32, 0x37, 0x41, 0x2c, 0x46, 0x30, 0x36, 0x36, 0x42, 0x42, 0x29, 0x1b, 0x4a, 0x4a, 0x4d, 0x26, 0x60, 0x0b, 0x17, 0x36, 0x44, 0x45, 0x66, 0x3e, 0x44, 0x44, 0x1a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x15, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0c, 0x2c, 0x32, 0x32, 0x38, 0x37, 0x32, 0x37, 0x30, 0x36, 0x4c, 0x31, 0x1e, 0x10, 0x1f, 0x52, 0x69, 0x52, 0x07, 0x2c, 0x10, 0x36, 0x62, 0x6a, 0x44, 0x6b, 0x3e, 0x44, 0x6c, 0x30, 0x09, 0x05, 0x05, 0x25, 0x54, 0x19, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x25, 0x2c, 0x37, 0x38, 0x37, 0x2c, 0x32, 0x32, 0x46, 0x30, 0x46, 0x4c, 0x31, 0x66, 0x4c, 0x36, 0x1a, 0x1a, 0x17, 0x37, 0x37, 0x10, 0x31, 0x62, 0x45, 0x4c, 0x3e, 0x44, 0x62, 0x30, 0x09, 0x05, 0x0a, 0x70, 0x71, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x22, 0x32, 0x32, 0x38, 0x41, 0x41, 0x38, 0x2d, 0x46, 0x66, 0x44, 0x6c, 0x6c, 0x6c, 0x3d, 0x3a, 0x42, 0x31, 0x32, 0x32, 0x32, 0x33, 0x33, 0x30, 0x36, 0x3e, 0x3e, 0x31, 0x07, 0x05, 0x12, 0x6e, 0x72, 0x09, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x2d, 0x2c, 0x38, 0x32, 0x41, 0x37, 0x2d, 0x46, 0x66, 0x6a, 0x6c, 0x6d, 0x6d, 0x6c, 0x3d, 0x3d, 0x31, 0x38, 0x38, 0x39, 0x33, 0x39, 0x36, 0x30, 0x30, 0x66, 0x30, 0x40, 0x4d, 0x5f, 0x4d, 0x4d, 0x05, 0x05, 0x05, 0x15, 0x04, 0x03, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x09, 0x5a, 0x2d, 0x32, 0x32, 0x37, 0x37, 0x32, 0x38, 0x46, 0x46, 0x66, 0x45, 0x44, 0x62, 0x44, 0x44, 0x3e, 0x31, 0x31, 0x31, 0x31, 0x31, 0x33, 0x37, 0x30, 0x10, 0x06, 0x05, 0x12, 0x0a, 0x05, 0x05, 0x05, 0x08, 0x68, 0x73, 0x05, 0x04, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x35, 0x22, 0x32, 0x32, 0x32, 0x3c, 0x37, 0x37, 0x2d, 0x39, 0x39, 0x39, 0x36, 0x36, 0x6b, 0x3e, 0x3e, 0x3e, 0x3e, 0x31, 0x4c, 0x39, 0x2d, 0x10, 0x16, 0x2a, 0x05, 0x05, 0x74, 0x74, 0x05, 0x05, 0x0c, 0x75, 0x5f, 0x1c, 0x05, 0x05, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x40, 0x2c, 0x32, 0x32, 0x32, 0x41, 0x37, 0x41, 0x2c, 0x2c, 0x41, 0x2c, 0x33, 0x36, 0x31, 0x36, 0x31, 0x31, 0x17, 0x46, 0x2c, 0x16, 0x40, 0x05, 0x05, 0x05, 0x05, 0x20, 0x5f, 0x4d, 0x72, 0x76, 0x06, 0x25, 0x4a, 0x05, 0x05, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x40, 0x0b, 0x2d, 0x37, 0x2d, 0x2c, 0x2c, 0x37, 0x37, 0x38, 0x2c, 0x37, 0x2c, 0x10, 0x10, 0x39, 0x30, 0x0b, 0x2c, 0x11, 0x09, 0x05, 0x09, 0x4a, 0x05, 0x05, 0x19, 0x1d, 0x26, 0x76, 0x08, 0x05, 0x05, 0x05, 0x15, 0x25, 0x4d, 0x53, 0x77, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4d, 0x5a, 0x2c, 0x37, 0x2d, 0x2c, 0x37, 0x37, 0x39, 0x39, 0x33, 0x38, 0x2c, 0x2d, 0x2d, 0x2c, 0x5e, 0x2a, 0x05, 0x15, 0x3b, 0x17, 0x1f, 0x19, 0x05, 0x06, 0x26, 0x60, 0x5f, 0x0c, 0x05, 0x05, 0x05, 0x35, 0x68, 0x78, 0x56, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x35, 0x2c, 0x2c, 0x2c, 0x37, 0x32, 0x37, 0x2c, 0x37, 0x32, 0x46, 0x33, 0x46, 0x39, 0x11, 0x15, 0x05, 0x05, 0x18, 0x31, 0x44, 0x6a, 0x30, 0x6e, 0x2b, 0x4b, 0x11, 0x5f, 0x63, 0x72, 0x54, 0x20, 0x74, 0x58, 0x25, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x15, 0x0b, 0x2c, 0x38, 0x2d, 0x39, 0x39, 0x2d, 0x37, 0x3c, 0x32, 0x37, 0x0b, 0x18, 0x05, 0x05, 0x05, 0x4e, 0x26, 0x32, 0x45, 0x6a, 0x46, 0x2b, 0x72, 0x4e, 0x05, 0x35, 0x0a, 0x75, 0x5f, 0x70, 0x08, 0x09, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x35, 0x22, 0x2d, 0x30, 0x6b, 0x6b, 0x66, 0x36, 0x30, 0x36, 0x4c, 0x36, 0x30, 0x18, 0x05, 0x05, 0x05, 0x09, 0x4b, 0x32, 0x46, 0x66, 0x38, 0x0b, 0x09, 0x05, 0x05, 0x05, 0x05, 0x09, 0x05, 0x05, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0a, 0x2c, 0x2c, 0x31, 0x62, 0x62, 0x6b, 0x31, 0x45, 0x44, 0x44, 0x45, 0x31, 0x10, 0x0c, 0x4d, 0x0c, 0x08, 0x0b, 0x3c, 0x32, 0x33, 0x66, 0x17, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x09, 0x22, 0x2c, 0x2d, 0x31, 0x45, 0x6b, 0x36, 0x31, 0x6b, 0x62, 0x45, 0x6a, 0x66, 0x30, 0x0b, 0x2c, 0x2c, 0x2c, 0x2c, 0x37, 0x46, 0x6b, 0x44, 0x62, 0x5e, 0x05, 0x05, 0x05, 0x05, 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0c, 0x1d, 0x2c, 0x39, 0x36, 0x4c, 0x30, 0x30, 0x30, 0x36, 0x4c, 0x66, 0x4c, 0x36, 0x30, 0x37, 0x41, 0x2c, 0x2d, 0x2c, 0x3c, 0x33, 0x6b, 0x44, 0x44, 0x39, 0x09, 0x05, 0x05, 0x04, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x2d, 0x2d, 0x2d, 0x36, 0x39, 0x2d, 0x32, 0x38, 0x38, 0x46, 0x6a, 0x6d, 0x3d, 0x62, 0x46, 0x3c, 0x37, 0x2d, 0x32, 0x32, 0x32, 0x38, 0x4c, 0x30, 0x16, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0a, 0x37, 0x38, 0x38, 0x39, 0x37, 0x2c, 0x37, 0x37, 0x30, 0x45, 0x6d, 0x6d, 0x62, 0x62, 0x38, 0x3c, 0x3c, 0x32, 0x37, 0x32, 0x32, 0x32, 0x2c, 0x14, 0x15, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x6e, 0x37, 0x38, 0x38, 0x38, 0x37, 0x2c, 0x2d, 0x30, 0x31, 0x62, 0x6a, 0x6d, 0x6a, 0x6a, 0x46, 0x32, 0x32, 0x37, 0x37, 0x32, 0x30, 0x17, 0x29, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4a, 0x0b, 0x38, 0x38, 0x38, 0x2c, 0x2c, 0x0b, 0x2d, 0x39, 0x4c, 0x45, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x38, 0x37, 0x2c, 0x41, 0x18, 0x1c, 0x0c, 0x05, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x15, 0x0b, 0x2d, 0x38, 0x38, 0x37, 0x2c, 0x2c, 0x2c, 0x37, 0x32, 0x4c, 0x6b, 0x44, 0x44, 0x45, 0x6a, 0x45, 0x38, 0x37, 0x1c, 0x09, 0x05, 0x05, 0x04, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x09, 0x1d, 0x38, 0x38, 0x38, 0x38, 0x2c, 0x3c, 0x37, 0x37, 0x32, 0x32, 0x46, 0x36, 0x1e, 0x6b, 0x4c, 0x46, 0x32, 0x22, 0x09, 0x05, 0x05, 0x04, 0x03, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x37, 0x32, 0x37, 0x38, 0x38, 0x37, 0x32, 0x3c, 0x32, 0x32, 0x37, 0x38, 0x2d, 0x2d, 0x38, 0x2c, 0x2c, 0x4f, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x3c, 0x37, 0x41, 0x38, 0x2d, 0x37, 0x37, 0x3c, 0x32, 0x3c, 0x32, 0x37, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0c, 0x41, 0x3c, 0x3c, 0x38, 0x32, 0x3c, 0x3c, 0x3c, 0x41, 0x32, 0x41, 0x37, 0x2c, 0x2c, 0x41, 0x38, 0x45, 0x18, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x2a, 0x2c, 0x3c, 0x37, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x37, 0x2c, 0x2c, 0x2c, 0x2c, 0x4c, 0x45, 0x6a, 0x1a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11, 0x2c, 0x37, 0x41, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x41, 0x37, 0x37, 0x4c, 0x44, 0x6d, 0x6a, 0x1a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x5a, 0x2c, 0x41, 0x3c, 0x3c, 0x3c, 0x32, 0x2c, 0x32, 0x2c, 0x2c, 0x38, 0x38, 0x36, 0x45, 0x62, 0x44, 0x45, 0x29, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x2a, 0x2c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x37, 0x37, 0x32, 0x37, 0x39, 0x4c, 0x4c, 0x45, 0x62, 0x44, 0x62, 0x30, 0x2a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x4a, 0x5a, 0x41, 0x3c, 0x3c, 0x3c, 0x3c, 0x32, 0x3c, 0x37, 0x37, 0x2d, 0x46, 0x4c, 0x6b, 0x6b, 0x45, 0x3e, 0x36, 0x29, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x27, 0x3c, 0x37, 0x3c, 0x3c, 0x37, 0x37, 0x32, 0x38, 0x37, 0x37, 0x37, 0x38, 0x39, 0x36, 0x4c, 0x30, 0x10, 0x16, 0x09, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x04, 0x05, 0x05, 0x25, 0x1d, 0x37, 0x37, 0x41, 0x32, 0x3c, 0x32, 0x41, 0x37, 0x32, 0x2c, 0x41, 0x37, 0x2c, 0x32, 0x37, 0x2c, 0x2c, 0x5a, 0x0c, 0x05, 0x05, 0x05, 0x04, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x05, 0x05, 0x15, 0x5a, 0x37, 0x2c, 0x41, 0x2c, 0x2c, 0x41, 0x37, 0x41, 0x41, 0x3c, 0x2c, 0x41, 0x41, 0x3c, 0x37, 0x2c, 0x39, 0x0b, 0x0b, 0x25, 0x05, 0x05, 0x05, 0x05, 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x2a, 0x22, 0x2d, 0x37, 0x2c, 0x3c, 0x1d, 0x2c, 0x38, 0x2c, 0x41, 0x2c, 0x2c, 0x2d, 0x39, 0x37, 0x3c, 0x37, 0x30, 0x1a, 0x5e, 0x6e, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x2a, 0x6e, 0x0b, 0x2d, 0x38, 0x41, 0x41, 0x6e, 0x5a, 0x2c, 0x41, 0x32, 0x38, 0x32, 0x39, 0x3f, 0x6f, 0x16, 0x37, 0x1a, 0x1f, 0x1f, 0x16, 0x1d, 0x0c, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x09, 0x40, 0x07, 0x2c, 0x37, 0x2c, 0x2d, 0x2c, 0x1d, 0x0e, 0x09, 0x0b, 0x4b, 0x07, 0x41, 0x38, 0x2d, 0x10, 0x2d, 0x10, 0x0b, 0x2b, 0x33, 0x3f, 0x21, 0x29, 0x07, 0x5e, 0x2f, 0x12, 0x08, 0x2a, 0x0c, 0x25, 0x09, 0x09, 0x09, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x19, 0x40, 0x28, 0x22, 0x2c, 0x38, 0x32, 0x32, 0x32, 0x1d, 0x0e, 0x19, 0x05, 0x35, 0x2c, 0x4b, 0x70, 0x0b, 0x32, 0x2c, 0x16, 0x16, 0x16, 0x0b, 0x22, 0x26, 0x0b, 0x10, 0x3f, 0x29, 0x1f, 0x47, 0x1f, 0x1f, 0x5e, 0x0b, 0x4b, 0x74, 0x84, 0x74, 0x84, 0x06, 0x35, 0x09, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x09, 0x4d, 0x27, 0x0a, 0x22, 0x1d, 0x2c, 0x2c, 0x37, 0x32, 0x41, 0x41, 0x16, 0x27, 0x15, 0x09, 0x4a, 0x09, 0x28, 0x2d, 0x0b, 0x76, 0x2c, 0x37, 0x2d, 0x37, 0x32, 0x37, 0x0b, 0x0b, 0x5e, 0x5a, 0x4b, 0x0b, 0x0b, 0x07, 0x6e, 0x16, 0x5e, 0x10, 0x76, 0x5c, 0x68, 0x79, 0x7a, 0x53, 0x71, 0x54, 0x5d, 0x08, 0x4d, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x04, 0x05, 0x05, 0x05, 0x25, 0x27, 0x28, 0x0b, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x41, 0x41, 0x41, 0x22, 0x11, 0x35, 0x4d, 0x4d, 0x35, 0x1c, 0x06, 0x0a, 0x22, 0x38, 0x38, 0x37, 0x38, 0x38, 0x38, 0x2d, 0x39, 0x39, 0x39, 0x10, 0x39, 0x10, 0x4b, 0x12, 0x08, 0x35, 0x67, 0x2a, 0x08, 0x74, 0x70, 0x81, 0x55, 0x78, 0x79, 0x57, 0x53, 0x71, 0x71, 0x73, 0x84, 0x25, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x05, 0x09, 0x27, 0x16, 0x0b, 0x2c, 0x2d, 0x2c, 0x41, 0x41, 0x1d, 0x22, 0x5a, 0x0f, 0x14, 0x0a, 0x28, 0x0a, 0x28, 0x28, 0x28, 0x6e, 0x5a, 0x65, 0x1d, 0x0b, 0x2d, 0x38, 0x46, 0x38, 0x38, 0x38, 0x39, 0x2d, 0x46, 0x39, 0x30, 0x39, 0x4b, 0x68, 0x79, 0x7a, 0x57, 0x67, 0x67, 0x56, 0x53, 0x71, 0x68, 0x7e, 0x85, 0x59, 0x73, 0x79, 0x54, 0x7a, 0x54, 0x06, 0x1c, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x4d, 0x16, 0x0b, 0x10, 0x39, 0x2d, 0x0b, 0x28, 0x06, 0x2a, 0x25, 0x35, 0x06, 0x11, 0x0a, 0x28, 0x07, 0x5a, 0x22, 0x26, 0x5a, 0x41, 0x7b, 0x7c, 0x60, 0x76, 0x22, 0x1d, 0x32, 0x38, 0x46, 0x46, 0x46, 0x38, 0x38, 0x38, 0x38, 0x2b, 0x75, 0x7d, 0x7e, 0x55, 0x78, 0x7a, 0x57, 0x57, 0x57, 0x71, 0x20, 0x68, 0x55, 0x85, 0x7a, 0x57, 0x53, 0x71, 0x57, 0x5d, 0x19, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x0c, 0x16, 0x0b, 0x30, 0x39, 0x18, 0x2a, 0x09, 0x05, 0x4e, 0x19, 0x25, 0x0c, 0x27, 0x11, 0x0a, 0x0a, 0x2f, 0x5a, 0x5a, 0x26, 0x5a, 0x7b, 0x7c, 0x7c, 0x61, 0x7f, 0x7f, 0x7f, 0x76, 0x22, 0x22, 0x0b, 0x2d, 0x0b, 0x2d, 0x2d, 0x33, 0x0b, 0x5f, 0x80, 0x7d, 0x5c, 0x81, 0x55, 0x59, 0x59, 0x73, 0x73, 0x54, 0x5c, 0x5c, 0x7e, 0x55, 0x59, 0x73, 0x7a, 0x71, 0x19, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x05, 0x05, 0x09, 0x25, 0x08, 0x07, 0x5e, 0x10, 0x22, 0x1c, 0x4a, 0x05, 0x09, 0x05, 0x15, 0x4d, 0x19, 0x19, 0x4d, 0x08, 0x12, 0x74, 0x0f, 0x6e, 0x5a, 0x26, 0x1d, 0x7b, 0x7b, 0x7c, 0x7c, 0x7c, 0x61, 0x5b, 0x82, 0x82, 0x80, 0x80, 0x82, 0x7f, 0x7f, 0x7f, 0x7f, 0x5b, 0x7f, 0x82, 0x80, 0x7d, 0x5c, 0x7e, 0x79, 0x54, 0x54, 0x7a, 0x73, 0x0f, 0x2a, 0x25, 0x19, 0x09, 0x4a, 0x05, 0x05, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x09, 0x4d, 0x2a, 0x06, 0x74, 0x28, 0x22, 0x22, 0x2d, 0x2c, 0x0e, 0x05, 0x05, 0x05, 0x05, 0x05, 0x3b, 0x07, 0x19, 0x09, 0x25, 0x0c, 0x27, 0x12, 0x0f, 0x2f, 0x26, 0x26, 0x1d, 0x65, 0x65, 0x7c, 0x7c, 0x7b, 0x7c, 0x7b, 0x7b, 0x60, 0x5b, 0x7f, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x80, 0x80, 0x83, 0x83, 0x81, 0x7e, 0x59, 0x73, 0x73, 0x84, 0x5d, 0x25, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x19, 0x08, 0x12, 0x0a, 0x0f, 0x6e, 0x5a, 0x26, 0x22, 0x2c, 0x2c, 0x0b, 0x27, 0x05, 0x05, 0x05, 0x15, 0x1e, 0x1e, 0x6f, 0x0c, 0x09, 0x15, 0x0c, 0x20, 0x12, 0x0f, 0x6e, 0x5a, 0x26, 0x26, 0x26, 0x65, 0x65, 0x65, 0x65, 0x7b, 0x7c, 0x7b, 0x65, 0x7b, 0x61, 0x61, 0x60, 0x64, 0x64, 0x64, 0x5b, 0x5b, 0x5f, 0x63, 0x70, 0x63, 0x58, 0x5d, 0x2a, 0x15, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x4a, 0x4d, 0x27, 0x11, 0x0a, 0x28, 0x6e, 0x5a, 0x26, 0x65, 0x41, 0x1d, 0x2c, 0x2c, 0x5e, 0x29, 0x0e, 0x14, 0x17, 0x31, 0x6b, 0x30, 0x14, 0x25, 0x09, 0x15, 0x4d, 0x08, 0x74, 0x0a, 0x0f, 0x2f, 0x5a, 0x26, 0x26, 0x1d, 0x1d, 0x1d, 0x2b, 0x65, 0x1d, 0x41, 0x65, 0x65, 0x7b, 0x65, 0x65, 0x1d, 0x6e, 0x74, 0x5d, 0x1c, 0x25, 0x15, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x09, 0x19, 0x4d, 0x08, 0x06, 0x0a, 0x2f, 0x6e, 0x2f, 0x6e, 0x26, 0x41, 0x7b, 0x65, 0x41, 0x37, 0x33, 0x30, 0x36, 0x36, 0x4c, 0x6b, 0x66, 0x30, 0x14, 0x35, 0x4a, 0x09, 0x15, 0x15, 0x25, 0x25, 0x0c, 0x1c, 0x08, 0x06, 0x5d, 0x5d, 0x5d, 0x0e, 0x06, 0x12, 0x06, 0x08, 0x1c, 0x2a, 0x0c, 0x19, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x09, 0x09, 0x19, 0x35, 0x08, 0x12, 0x28, 0x2f, 0x2f, 0x6e, 0x5a, 0x41, 0x7c, 0x3c, 0x3c, 0x2c, 0x41, 0x2d, 0x2d, 0x39, 0x30, 0x4c, 0x4c, 0x66, 0x66, 0x31, 0x24, 0x20, 0x4a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x4a, 0x09, 0x4a, 0x09, 0x09, 0x05, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x09, 0x15, 0x0c, 0x1c, 0x12, 0x28, 0x2f, 0x5a, 0x1d, 0x7c, 0x7b, 0x41, 0x7b, 0x3c, 0x7b, 0x3c, 0x41, 0x41, 0x5a, 0x16, 0x28, 0x14, 0x14, 0x14, 0x3b, 0x12, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x4a, 0x09, 0x15, 0x1c, 0x12, 0x12, 0x0a, 0x0f, 0x2f, 0x07, 0x2f, 0x0a, 0x12, 0x27, 0x0c, 0x4d, 0x15, 0x09, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x09, 0x15, 0x15, 0x15, 0x19, 0x4e, 0x4e, 0x05, 0x4a, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+unsigned int logo_img_size = sizeof(logo_img);
diff --git a/sys/dev/syscons/logo/logo_saver.c b/sys/dev/syscons/logo/logo_saver.c
new file mode 100644
index 000000000000..c77edfbbd0a4
--- /dev/null
+++ b/sys/dev/syscons/logo/logo_saver.c
@@ -0,0 +1,174 @@
+/*-
+ * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/syslog.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define SAVER_NAME "logo_saver"
+
+#define SET_ORIGIN(adp, o) do { \
+ int oo = o; \
+ if (oo != last_origin) \
+ vidd_set_win_org(adp, last_origin = oo); \
+ } while (0)
+
+extern unsigned int logo_w;
+extern unsigned int logo_h;
+extern unsigned char logo_pal[];
+extern unsigned char logo_img[];
+extern unsigned int logo_img_size;
+
+static u_char *vid;
+static int banksize, scrmode, bpsl, scrw, scrh;
+static int blanked;
+
+static void
+logo_blit(video_adapter_t *adp, int x, int y)
+{
+ int d, l, o, p;
+ int last_origin = -1;
+
+ for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
+ o += banksize;
+ SET_ORIGIN(adp, o);
+
+ for (d = 0; d < logo_img_size; d += logo_w) {
+ if (p + logo_w < banksize) {
+ bcopy(logo_img + d, vid + p, logo_w);
+ p += bpsl;
+ } else if (p < banksize) {
+ l = banksize - p;
+ bcopy(logo_img + d, vid + p, l);
+ SET_ORIGIN(adp, (o += banksize));
+ bcopy(logo_img + d + l, vid, logo_w - l);
+ p += bpsl - banksize;
+ } else {
+ p -= banksize;
+ SET_ORIGIN(adp, (o += banksize));
+ bcopy(logo_img + d, vid + p, logo_w);
+ p += bpsl;
+ }
+ }
+}
+
+static void
+logo_update(video_adapter_t *adp)
+{
+ static int xpos = 0, ypos = 0;
+ static int xinc = 1, yinc = 1;
+
+ /* Turn when you hit the edge */
+ if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
+ xinc = -xinc;
+ if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
+ yinc = -yinc;
+ xpos += xinc;
+ ypos += yinc;
+
+ /* XXX Relies on margin around logo to erase trail */
+ logo_blit(adp, xpos, ypos);
+}
+
+static int
+logo_saver(video_adapter_t *adp, int blank)
+{
+ int pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ vidd_set_mode(adp, scrmode);
+ vidd_load_palette(adp, logo_pal);
+ vidd_set_border(adp, 0);
+ blanked++;
+ vid = (u_char *)adp->va_window;
+ banksize = adp->va_window_size;
+ bpsl = adp->va_line_width;
+ splx(pl);
+ vidd_clear(adp);
+ }
+ logo_update(adp);
+ } else {
+ blanked = 0;
+ }
+ return (0);
+}
+
+static int
+logo_init(video_adapter_t *adp)
+{
+ video_info_t info;
+
+ if (!vidd_get_info(adp, M_VESA_CG800x600, &info)) {
+ scrmode = M_VESA_CG800x600;
+ } else if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
+ scrmode = M_VGA_CG320;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
+ scrmode = M_PC98_PEGC640x480;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
+ scrmode = M_PC98_PEGC640x400;
+ } else {
+ log(LOG_NOTICE,
+ "%s: the console does not support M_VGA_CG320\n",
+ SAVER_NAME);
+ return (ENODEV);
+ }
+
+ scrw = info.vi_width;
+ scrh = info.vi_height;
+
+ return (0);
+}
+
+static int
+logo_term(video_adapter_t *adp)
+{
+ return (0);
+}
+
+static scrn_saver_t logo_module = {
+ SAVER_NAME,
+ logo_init,
+ logo_term,
+ logo_saver,
+ NULL
+};
+
+SAVER_MODULE(logo_saver, logo_module);
diff --git a/sys/dev/syscons/rain/rain_saver.c b/sys/dev/syscons/rain/rain_saver.c
new file mode 100644
index 000000000000..395313716dbc
--- /dev/null
+++ b/sys/dev/syscons/rain/rain_saver.c
@@ -0,0 +1,181 @@
+/*-
+ * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/syslog.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define SAVER_NAME "rain_saver"
+#ifdef MAX
+#undef MAX
+#endif
+#define MAX 63 /* number of colors (in addition to black) */
+#define INCREMENT 4 /* increment between colors */
+
+#define RED(n) ((n) * 3 + 0)
+#define GREEN(n) ((n) * 3 + 1)
+#define BLUE(n) ((n) * 3 + 2)
+
+#define SET_ORIGIN(adp, o) do { \
+ int oo = o; \
+ if (oo != last_origin) \
+ vidd_set_win_org(adp, last_origin = oo); \
+ } while (0)
+
+static u_char *vid;
+static int banksize, scrmode, bpsl, scrw, scrh;
+static u_char rain_pal[768];
+static int blanked;
+
+static void
+rain_update(video_adapter_t *adp)
+{
+ int i, t;
+
+ t = rain_pal[BLUE(MAX)];
+ for (i = MAX; i > 1; i--)
+ rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)];
+ rain_pal[BLUE(1)] = t;
+ vidd_load_palette(adp, rain_pal);
+}
+
+static int
+rain_saver(video_adapter_t *adp, int blank)
+{
+ int i, j, o, p, pl;
+ u_char temp;
+ int last_origin = -1;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ vidd_set_mode(adp, scrmode);
+ vidd_load_palette(adp, rain_pal);
+ vidd_set_border(adp, 0);
+ blanked++;
+ vid = (u_char *)adp->va_window;
+ banksize = adp->va_window_size;
+ bpsl = adp->va_line_width;
+ splx(pl);
+ for (i = 0; i < bpsl*scrh; i += banksize) {
+ SET_ORIGIN(adp, i);
+ if ((bpsl * scrh - i) < banksize)
+ bzero(vid, bpsl * scrh - i);
+ else
+ bzero(vid, banksize);
+ }
+ SET_ORIGIN(adp, 0);
+ for (i = 0, o = 0, p = 0; i < scrw; i += 2, p += 2) {
+ if (p > banksize) {
+ p -= banksize;
+ o += banksize;
+ SET_ORIGIN(adp, o);
+ }
+ vid[p] = 1 + (random() % MAX);
+ }
+ o = 0; p = 0;
+ for (j = 1; j < scrh; j++)
+ for (i = 0, p = bpsl * (j - 1) - o; i < scrw; i += 2, p+= 2) {
+ while (p > banksize) {
+ p -= banksize;
+ o += banksize;
+ }
+ SET_ORIGIN(adp, o);
+ temp = (vid[p] < MAX) ? 1 + vid[p] : 1;
+ if (p + bpsl < banksize) {
+ vid[p + bpsl] = temp;
+ } else {
+ SET_ORIGIN(adp, o + banksize);
+ vid[p + bpsl - banksize] = temp;
+ }
+ }
+ }
+
+ /* update display */
+ rain_update(adp);
+ } else {
+ blanked = 0;
+ }
+ return (0);
+}
+
+static int
+rain_init(video_adapter_t *adp)
+{
+ video_info_t info;
+ int i;
+
+ if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
+ scrmode = M_VGA_CG320;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
+ scrmode = M_PC98_PEGC640x480;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
+ scrmode = M_PC98_PEGC640x400;
+ } else {
+ log(LOG_NOTICE,
+ "%s: the console does not support M_VGA_CG320\n",
+ SAVER_NAME);
+ return (ENODEV);
+ }
+
+ scrw = info.vi_width;
+ scrh = info.vi_height;
+
+ /* intialize the palette */
+ for (i = 1; i < MAX; i++)
+ rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)] + INCREMENT;
+
+ return (0);
+}
+
+static int
+rain_term(video_adapter_t *adp)
+{
+ return (0);
+}
+
+static scrn_saver_t rain_module = {
+ SAVER_NAME,
+ rain_init,
+ rain_term,
+ rain_saver,
+ NULL
+};
+
+SAVER_MODULE(rain_saver, rain_module);
diff --git a/sys/dev/syscons/scgfbrndr.c b/sys/dev/syscons/scgfbrndr.c
new file mode 100644
index 000000000000..20679b70d452
--- /dev/null
+++ b/sys/dev/syscons/scgfbrndr.c
@@ -0,0 +1,366 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright (c) 2000 Andrew Miklic
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+#include "opt_gfb.h"
+#ifdef __powerpc__
+#include "opt_ofwfb.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/fbio.h>
+#include <sys/consio.h>
+
+#include <machine/bus.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/syscons/syscons.h>
+
+#ifndef SC_RENDER_DEBUG
+#define SC_RENDER_DEBUG 0
+#endif
+
+static vr_clear_t gfb_clear;
+static vr_draw_border_t gfb_border;
+static vr_draw_t gfb_draw;
+static vr_set_cursor_t gfb_cursor_shape;
+static vr_draw_cursor_t gfb_cursor;
+static vr_blink_cursor_t gfb_blink;
+#ifndef SC_NO_CUTPASTE
+static vr_draw_mouse_t gfb_mouse;
+#else
+#define gfb_mouse (vr_draw_mouse_t *)gfb_nop
+#endif
+
+static void gfb_nop(scr_stat *scp);
+
+sc_rndr_sw_t txtrndrsw = {
+ (vr_init_t *)gfb_nop,
+ gfb_clear,
+ gfb_border,
+ gfb_draw,
+ gfb_cursor_shape,
+ gfb_cursor,
+ gfb_blink,
+ (vr_set_mouse_t *)gfb_nop,
+ gfb_mouse,
+};
+
+#ifdef SC_PIXEL_MODE
+sc_rndr_sw_t gfbrndrsw = {
+ (vr_init_t *)gfb_nop,
+ gfb_clear,
+ gfb_border,
+ gfb_draw,
+ gfb_cursor_shape,
+ gfb_cursor,
+ gfb_blink,
+ (vr_set_mouse_t *)gfb_nop,
+ gfb_mouse,
+};
+#endif /* SC_PIXEL_MODE */
+
+#ifndef SC_NO_MODE_CHANGE
+sc_rndr_sw_t grrndrsw = {
+ (vr_init_t *)gfb_nop,
+ (vr_clear_t *)gfb_nop,
+ gfb_border,
+ (vr_draw_t *)gfb_nop,
+ (vr_set_cursor_t *)gfb_nop,
+ (vr_draw_cursor_t *)gfb_nop,
+ (vr_blink_cursor_t *)gfb_nop,
+ (vr_set_mouse_t *)gfb_nop,
+ (vr_draw_mouse_t *)gfb_nop,
+};
+#endif /* SC_NO_MODE_CHANGE */
+
+#ifndef SC_NO_CUTPASTE
+#ifdef __sparc64__
+static u_char mouse_pointer[22 * 2] = {
+ 0x00, 0x00, /* ............ */
+ 0x80, 0x00, /* *........... */
+ 0xc0, 0x00, /* **.......... */
+ 0xe0, 0x00, /* ***......... */
+ 0xf0, 0x00, /* ****........ */
+ 0xf8, 0x00, /* *****....... */
+ 0xfc, 0x00, /* ******...... */
+ 0xfe, 0x00, /* *******..... */
+ 0xff, 0x00, /* ********.... */
+ 0xff, 0x80, /* *********... */
+ 0xfc, 0xc0, /* ******..**.. */
+ 0xdc, 0x00, /* **.***...... */
+ 0x8e, 0x00, /* *...***..... */
+ 0x0e, 0x00, /* ....***..... */
+ 0x07, 0x00, /* .....***.... */
+ 0x04, 0x00, /* .....*...... */
+ 0x00, 0x00, /* ............ */
+ 0x00, 0x00, /* ............ */
+ 0x00, 0x00, /* ............ */
+ 0x00, 0x00, /* ............ */
+ 0x00, 0x00, /* ............ */
+ 0x00, 0x00 /* ............ */
+};
+#else
+static u_char mouse_pointer[16] = {
+ 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
+ 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
+};
+#endif
+#endif
+
+static void
+gfb_nop(scr_stat *scp)
+{
+}
+
+/* text mode renderer */
+
+static void
+gfb_clear(scr_stat *scp, int c, int attr)
+{
+ vidd_clear(scp->sc->adp);
+}
+
+static void
+gfb_border(scr_stat *scp, int color)
+{
+ vidd_set_border(scp->sc->adp, color);
+}
+
+static void
+gfb_draw(scr_stat *scp, int from, int count, int flip)
+{
+ int c;
+ int a;
+ int i, n;
+ video_adapter_t *adp;
+
+ adp = scp->sc->adp;
+
+ /*
+ Determine if we need to scroll based on the offset
+ and the number of characters to be displayed...
+ */
+ if (from + count > scp->xsize*scp->ysize) {
+
+ /*
+ Calculate the number of characters past the end of the
+ visible screen...
+ */
+ count = (from + count) -
+ (adp->va_info.vi_width * adp->va_info.vi_height);
+
+ /*
+ Calculate the number of rows past the end of the visible
+ screen...
+ */
+ n = (count / adp->va_info.vi_width) + 1;
+
+ /* Scroll to make room for new text rows... */
+ vidd_copy(adp, n, 0, n);
+#if 0
+ vidd_clear(adp, n);
+#endif
+
+ /* Display new text rows... */
+ vidd_puts(adp, from,
+ (u_int16_t *)sc_vtb_pointer(&scp->vtb, from), count);
+ }
+
+ /*
+ We don't need to scroll, so we can just put the characters
+ all-at-once...
+ */
+ else {
+
+ /*
+ Determine the method by which we are to display characters
+ (are we going to print forwards or backwards?
+ do we need to do a character-by-character copy, then?)...
+ */
+ if (flip)
+ for (i = count; i-- > 0; ++from) {
+ c = sc_vtb_getc(&scp->vtb, from);
+ a = sc_vtb_geta(&scp->vtb, from) >> 8;
+ vidd_putc(adp, from, c,
+ (a >> 4) | ((a & 0xf) << 4));
+ }
+ else {
+ vidd_puts(adp, from,
+ (u_int16_t *)sc_vtb_pointer(&scp->vtb, from),
+ count);
+ }
+ }
+}
+
+static void
+gfb_cursor_shape(scr_stat *scp, int base, int height, int blink)
+{
+ if (base < 0 || base >= scp->font_size)
+ return;
+ /* the caller may set height <= 0 in order to disable the cursor */
+#if 0
+ scp->cursor_base = base;
+ scp->cursor_height = height;
+#endif
+ vidd_set_hw_cursor_shape(scp->sc->adp, base, height, scp->font_size,
+ blink);
+}
+
+static int pxlblinkrate = 0;
+
+#if defined(__sparc64__) || defined(SC_OFWFB)
+static void
+gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ video_adapter_t *adp;
+ int a, c;
+
+ if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
+ return;
+
+ adp = scp->sc->adp;
+ if(blink) {
+ scp->status |= VR_CURSOR_BLINK;
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize);
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ vidd_set_hw_cursor(adp, -1, -1);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ } else {
+ scp->status &= ~VR_CURSOR_BLINK;
+ if(on) {
+ scp->status |= VR_CURSOR_ON;
+ vidd_putc(scp->sc->adp, scp->cursor_oldpos,
+ sc_vtb_getc(&scp->vtb, scp->cursor_oldpos),
+ sc_vtb_geta(&scp->vtb, scp->cursor_oldpos) >> 8);
+ a = sc_vtb_geta(&scp->vtb, at) >> 8;
+ c = sc_vtb_getc(&scp->vtb, at);
+ vidd_putc(scp->sc->adp, at, c,
+ (a >> 4) | ((a & 0xf) << 4));
+ scp->cursor_saveunder_attr = a;
+ scp->cursor_saveunder_char = c;
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ vidd_putc(scp->sc->adp, at,
+ scp->cursor_saveunder_char,
+ scp->cursor_saveunder_attr);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ }
+}
+#else
+static void
+gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ video_adapter_t *adp;
+
+ adp = scp->sc->adp;
+ if (scp->curs_attr.height <= 0)
+ /* the text cursor is disabled */
+ return;
+
+ if (on) {
+ if (!blink) {
+ scp->status |= VR_CURSOR_ON;
+ vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize);
+ } else if (++pxlblinkrate & 4) {
+ pxlblinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ if(scp->status & VR_CURSOR_ON)
+ vidd_set_hw_cursor(adp, at%scp->xsize,
+ at/scp->xsize);
+ else
+ vidd_set_hw_cursor(adp, -1, -1);
+ }
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ if (blink)
+ scp->status |= VR_CURSOR_BLINK;
+ else
+ scp->status &= ~VR_CURSOR_BLINK;
+}
+#endif
+
+static void
+gfb_blink(scr_stat *scp, int at, int flip)
+{
+ if (!(scp->status & VR_CURSOR_BLINK))
+ return;
+ if (!(++pxlblinkrate & 4))
+ return;
+ pxlblinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ gfb_cursor(scp, at, scp->status & VR_CURSOR_BLINK,
+ scp->status & VR_CURSOR_ON, flip);
+}
+
+#ifndef SC_NO_CUTPASTE
+
+static void
+gfb_mouse(scr_stat *scp, int x, int y, int on)
+{
+#ifdef __sparc64__
+ vidd_putm(scp->sc->adp, x, y, mouse_pointer,
+ on ? 0xffffffff : 0x0, 22, 12);
+#else
+ int i, pos;
+
+ if (on) {
+
+ /* Display the mouse pointer image... */
+ vidd_putm(scp->sc->adp, x, y, mouse_pointer,
+ 0xffffffff, 16, 8);
+ } else {
+
+ /*
+ Erase the mouse cursor image by redrawing the text
+ underneath it...
+ */
+ return;
+ pos = x*scp->xsize + y;
+ i = (y < scp->xsize - 1) ? 2 : 1;
+ (*scp->rndr->draw)(scp, pos, i, FALSE);
+ if (x < scp->ysize - 1)
+ (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
+ }
+#endif
+}
+
+#endif /* SC_NO_CUTPASTE */
diff --git a/sys/dev/syscons/schistory.c b/sys/dev/syscons/schistory.c
new file mode 100644
index 000000000000..860367b28102
--- /dev/null
+++ b/sys/dev/syscons/schistory.c
@@ -0,0 +1,326 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * Copyright (c) 1992-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#ifndef SC_NO_HISTORY
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/consio.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#if defined(__sparc64__) || defined(__powerpc__)
+#include <machine/sc_machdep.h>
+#else
+#include <machine/pc/display.h>
+#endif
+
+#include <dev/syscons/syscons.h>
+
+/*
+ * XXX Placeholder.
+ * This calculations should be dynamically scaled by number of seperate sc
+ * devices. A base value of 'extra_history_size' should be defined for
+ * each syscons unit, and added and subtracted from the dynamic
+ * 'extra_history_size' as units are added and removed. This way, each time
+ * a new syscons unit goes online, extra_history_size is automatically bumped.
+ */
+#define MAXSC 1
+
+#if !defined(SC_MAX_HISTORY_SIZE)
+#define SC_MAX_HISTORY_SIZE (1000 * MAXCONS * MAXSC)
+#endif
+
+#if !defined(SC_HISTORY_SIZE)
+#define SC_HISTORY_SIZE (ROW * 4)
+#endif
+
+#if (SC_HISTORY_SIZE * MAXCONS * MAXSC) > SC_MAX_HISTORY_SIZE
+#undef SC_MAX_HISTORY_SIZE
+#define SC_MAX_HISTORY_SIZE (SC_HISTORY_SIZE * MAXCONS * MAXSC)
+#endif
+
+/* local variables */
+static int extra_history_size
+ = SC_MAX_HISTORY_SIZE - SC_HISTORY_SIZE*MAXCONS;
+
+/* local functions */
+static void copy_history(sc_vtb_t *from, sc_vtb_t *to);
+static void history_to_screen(scr_stat *scp);
+
+/* allocate a history buffer */
+int
+sc_alloc_history_buffer(scr_stat *scp, int lines, int prev_ysize, int wait)
+{
+ /*
+ * syscons unconditionally allocates buffers upto
+ * SC_HISTORY_SIZE lines or scp->ysize lines, whichever
+ * is larger. A value greater than that is allowed,
+ * subject to extra_history_size.
+ */
+ sc_vtb_t *history;
+ sc_vtb_t *prev_history;
+ int cur_lines; /* current buffer size */
+ int min_lines; /* guaranteed buffer size */
+ int delta; /* lines to put back */
+
+ if (lines <= 0)
+ lines = SC_HISTORY_SIZE; /* use the default value */
+
+ /* make it at least as large as the screen size */
+ lines = imax(lines, scp->ysize);
+
+ /* remove the history buffer while we update it */
+ history = prev_history = scp->history;
+ scp->history = NULL;
+
+ /* calculate the amount of lines to put back to extra_history_size */
+ delta = 0;
+ if (prev_history) {
+ cur_lines = sc_vtb_rows(history);
+ min_lines = imax(SC_HISTORY_SIZE, prev_ysize);
+ if (cur_lines > min_lines)
+ delta = cur_lines - min_lines;
+ }
+
+ /* lines upto min_lines are always allowed. */
+ min_lines = imax(SC_HISTORY_SIZE, scp->ysize);
+ if (lines > min_lines) {
+ if (lines - min_lines > extra_history_size + delta) {
+ /* too many lines are requested */
+ scp->history = prev_history;
+ return EINVAL;
+ }
+ }
+
+ /* allocate a new buffer */
+ history = (sc_vtb_t *)malloc(sizeof(*history),
+ M_DEVBUF,
+ (wait) ? M_WAITOK : M_NOWAIT);
+ if (history != NULL) {
+ if (lines > min_lines)
+ extra_history_size -= lines - min_lines;
+ /* XXX error check? */
+ sc_vtb_init(history, VTB_RINGBUFFER, scp->xsize, lines,
+ NULL, wait);
+ /* FIXME: XXX no good? */
+ sc_vtb_clear(history, scp->sc->scr_map[0x20],
+ SC_NORM_ATTR << 8);
+ if (prev_history != NULL)
+ copy_history(prev_history, history);
+ scp->history_pos = sc_vtb_tail(history);
+ } else {
+ scp->history_pos = 0;
+ }
+
+ /* destroy the previous buffer */
+ if (prev_history != NULL) {
+ extra_history_size += delta;
+ sc_vtb_destroy(prev_history);
+ free(prev_history, M_DEVBUF);
+ }
+
+ scp->history = history;
+
+ return 0;
+}
+
+static void
+copy_history(sc_vtb_t *from, sc_vtb_t *to)
+{
+ int lines;
+ int cols;
+ int cols1;
+ int cols2;
+ int pos;
+ int i;
+
+ lines = sc_vtb_rows(from);
+ cols1 = sc_vtb_cols(from);
+ cols2 = sc_vtb_cols(to);
+ cols = imin(cols1, cols2);
+ pos = sc_vtb_tail(from);
+ for (i = 0; i < lines; ++i) {
+ sc_vtb_append(from, pos, to, cols);
+ if (cols < cols2)
+ sc_vtb_seek(to, sc_vtb_pos(to,
+ sc_vtb_tail(to),
+ cols2 - cols));
+ pos = sc_vtb_pos(from, pos, cols1);
+ }
+}
+
+void
+sc_free_history_buffer(scr_stat *scp, int prev_ysize)
+{
+ sc_vtb_t *history;
+ int cur_lines; /* current buffer size */
+ int min_lines; /* guaranteed buffer size */
+
+ history = scp->history;
+ scp->history = NULL;
+ if (history == NULL)
+ return;
+
+ cur_lines = sc_vtb_rows(history);
+ min_lines = imax(SC_HISTORY_SIZE, prev_ysize);
+ extra_history_size += (cur_lines > min_lines) ?
+ cur_lines - min_lines : 0;
+
+ sc_vtb_destroy(history);
+ free(history, M_DEVBUF);
+}
+
+/* copy entire screen into the top of the history buffer */
+void
+sc_hist_save(scr_stat *scp)
+{
+ sc_vtb_append(&scp->vtb, 0, scp->history, scp->xsize*scp->ysize);
+ scp->history_pos = sc_vtb_tail(scp->history);
+}
+
+/* restore the screen by copying from the history buffer */
+int
+sc_hist_restore(scr_stat *scp)
+{
+ int ret;
+
+ if (scp->history_pos != sc_vtb_tail(scp->history)) {
+ scp->history_pos = sc_vtb_tail(scp->history);
+ history_to_screen(scp);
+ ret = 0;
+ } else {
+ ret = 1;
+ }
+ sc_vtb_seek(scp->history, sc_vtb_pos(scp->history,
+ sc_vtb_tail(scp->history),
+ -scp->xsize*scp->ysize));
+ return ret;
+}
+
+/* copy screen-full of saved lines */
+static void
+history_to_screen(scr_stat *scp)
+{
+ int pos;
+ int i;
+
+ pos = scp->history_pos;
+ for (i = 1; i <= scp->ysize; ++i) {
+ pos = sc_vtb_pos(scp->history, pos, -scp->xsize);
+ sc_vtb_copy(scp->history, pos,
+ &scp->vtb, scp->xsize*(scp->ysize - i),
+ scp->xsize);
+ }
+ mark_all(scp);
+}
+
+/* go to the tail of the history buffer */
+void
+sc_hist_home(scr_stat *scp)
+{
+ scp->history_pos = sc_vtb_tail(scp->history);
+ history_to_screen(scp);
+}
+
+/* go to the top of the history buffer */
+void
+sc_hist_end(scr_stat *scp)
+{
+ scp->history_pos = sc_vtb_pos(scp->history, sc_vtb_tail(scp->history),
+ scp->xsize*scp->ysize);
+ history_to_screen(scp);
+}
+
+/* move one line up */
+int
+sc_hist_up_line(scr_stat *scp)
+{
+ if (sc_vtb_pos(scp->history, scp->history_pos, -(scp->xsize*scp->ysize))
+ == sc_vtb_tail(scp->history))
+ return -1;
+ scp->history_pos = sc_vtb_pos(scp->history, scp->history_pos,
+ -scp->xsize);
+ history_to_screen(scp);
+ return 0;
+}
+
+/* move one line down */
+int
+sc_hist_down_line(scr_stat *scp)
+{
+ if (scp->history_pos == sc_vtb_tail(scp->history))
+ return -1;
+ scp->history_pos = sc_vtb_pos(scp->history, scp->history_pos,
+ scp->xsize);
+ history_to_screen(scp);
+ return 0;
+}
+
+int
+sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+{
+ scr_stat *scp;
+ int error;
+
+ switch (cmd) {
+
+ case CONS_HISTORY: /* set history size */
+ scp = SC_STAT(tp);
+ if (*(int *)data <= 0)
+ return EINVAL;
+ if (scp->status & BUFFER_SAVED)
+ return EBUSY;
+ DPRINTF(5, ("lines:%d, ysize:%d, pool:%d\n",
+ *(int *)data, scp->ysize, extra_history_size));
+ error = sc_alloc_history_buffer(scp,
+ imax(*(int *)data, scp->ysize),
+ scp->ysize, TRUE);
+ DPRINTF(5, ("error:%d, rows:%d, pool:%d\n", error,
+ sc_vtb_rows(scp->history), extra_history_size));
+ return error;
+
+ case CONS_CLRHIST:
+ scp = SC_STAT(tp);
+ sc_vtb_clear(scp->history, scp->sc->scr_map[0x20],
+ SC_NORM_ATTR << 8);
+ return 0;
+ }
+
+ return ENOIOCTL;
+}
+
+#endif /* SC_NO_HISTORY */
diff --git a/sys/dev/syscons/scmouse.c b/sys/dev/syscons/scmouse.c
new file mode 100644
index 000000000000..2d998d403993
--- /dev/null
+++ b/sys/dev/syscons/scmouse.c
@@ -0,0 +1,906 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+#include <sys/limits.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mouse.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+#include <sys/random.h>
+#include <sys/signalvar.h>
+#include <sys/tty.h>
+
+#include <dev/syscons/syscons.h>
+
+#ifdef SC_TWOBUTTON_MOUSE
+#define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON3DOWN /* right button */
+#define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON2DOWN /* not really used */
+#else
+#define SC_MOUSE_PASTEBUTTON MOUSE_BUTTON2DOWN /* middle button */
+#define SC_MOUSE_EXTENDBUTTON MOUSE_BUTTON3DOWN /* right button */
+#endif /* SC_TWOBUTTON_MOUSE */
+
+#define SC_WAKEUP_DELTA 20
+
+/* for backward compatibility */
+#define OLD_CONS_MOUSECTL _IOWR('c', 10, old_mouse_info_t)
+
+typedef struct old_mouse_data {
+ int x;
+ int y;
+ int buttons;
+} old_mouse_data_t;
+
+typedef struct old_mouse_info {
+ int operation;
+ union {
+ struct old_mouse_data data;
+ struct mouse_mode mode;
+ } u;
+} old_mouse_info_t;
+
+#ifndef SC_NO_SYSMOUSE
+
+/* local variables */
+#ifndef SC_NO_CUTPASTE
+static int cut_buffer_size;
+static u_char *cut_buffer;
+#endif
+
+/* local functions */
+static void set_mouse_pos(scr_stat *scp);
+#ifndef SC_NO_CUTPASTE
+static int skip_spc_right(scr_stat *scp, int p);
+static int skip_spc_left(scr_stat *scp, int p);
+static void mouse_cut(scr_stat *scp);
+static void mouse_cut_start(scr_stat *scp);
+static void mouse_cut_end(scr_stat *scp);
+static void mouse_cut_word(scr_stat *scp);
+static void mouse_cut_line(scr_stat *scp);
+static void mouse_cut_extend(scr_stat *scp);
+#endif /* SC_NO_CUTPASTE */
+
+#ifndef SC_NO_CUTPASTE
+/* allocate a cut buffer */
+void
+sc_alloc_cut_buffer(scr_stat *scp, int wait)
+{
+ u_char *p;
+
+ if ((cut_buffer == NULL)
+ || (cut_buffer_size < scp->xsize * scp->ysize + 1)) {
+ p = cut_buffer;
+ cut_buffer = NULL;
+ if (p != NULL)
+ free(p, M_DEVBUF);
+ cut_buffer_size = scp->xsize * scp->ysize + 1;
+ p = (u_char *)malloc(cut_buffer_size,
+ M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT);
+ if (p != NULL)
+ p[0] = '\0';
+ cut_buffer = p;
+ }
+}
+#endif /* SC_NO_CUTPASTE */
+
+/* move mouse */
+void
+sc_mouse_move(scr_stat *scp, int x, int y)
+{
+ int s;
+
+ s = spltty();
+ scp->mouse_xpos = scp->mouse_oldxpos = x;
+ scp->mouse_ypos = scp->mouse_oldypos = y;
+ if (scp->font_size <= 0 || scp->font_width <= 0)
+ scp->mouse_pos = scp->mouse_oldpos = 0;
+ else
+ scp->mouse_pos = scp->mouse_oldpos =
+ (y/scp->font_size - scp->yoff)*scp->xsize + x/scp->font_width -
+ scp->xoff;
+ scp->status |= MOUSE_MOVED;
+ splx(s);
+}
+
+/* adjust mouse position */
+static void
+set_mouse_pos(scr_stat *scp)
+{
+ if (scp->mouse_xpos < scp->xoff*scp->font_width)
+ scp->mouse_xpos = scp->xoff*scp->font_width;
+ if (scp->mouse_ypos < scp->yoff*scp->font_size)
+ scp->mouse_ypos = scp->yoff*scp->font_size;
+ if (ISGRAPHSC(scp)) {
+ if (scp->mouse_xpos > scp->xpixel-1)
+ scp->mouse_xpos = scp->xpixel-1;
+ if (scp->mouse_ypos > scp->ypixel-1)
+ scp->mouse_ypos = scp->ypixel-1;
+ return;
+ } else {
+ if (scp->mouse_xpos > (scp->xsize + scp->xoff)*scp->font_width - 1)
+ scp->mouse_xpos = (scp->xsize + scp->xoff)*scp->font_width - 1;
+ if (scp->mouse_ypos > (scp->ysize + scp->yoff)*scp->font_size - 1)
+ scp->mouse_ypos = (scp->ysize + scp->yoff)*scp->font_size - 1;
+ }
+
+ if ((scp->mouse_xpos != scp->mouse_oldxpos || scp->mouse_ypos != scp->mouse_oldypos)
+ && (scp->font_size != 0 && scp->font_width != 0)) {
+ scp->status |= MOUSE_MOVED;
+ scp->mouse_pos =
+ (scp->mouse_ypos/scp->font_size - scp->yoff)*scp->xsize
+ + scp->mouse_xpos/scp->font_width - scp->xoff;
+#ifndef SC_NO_CUTPASTE
+ if ((scp->status & MOUSE_VISIBLE) && (scp->status & MOUSE_CUTTING))
+ mouse_cut(scp);
+#endif
+ }
+}
+
+#ifndef SC_NO_CUTPASTE
+
+void
+sc_draw_mouse_image(scr_stat *scp)
+{
+ if (ISGRAPHSC(scp))
+ return;
+
+ SC_VIDEO_LOCK(scp->sc);
+ (*scp->rndr->draw_mouse)(scp, scp->mouse_xpos, scp->mouse_ypos, TRUE);
+ scp->mouse_oldpos = scp->mouse_pos;
+ scp->mouse_oldxpos = scp->mouse_xpos;
+ scp->mouse_oldypos = scp->mouse_ypos;
+ scp->status |= MOUSE_VISIBLE;
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+void
+sc_remove_mouse_image(scr_stat *scp)
+{
+ int size;
+ int i;
+
+ if (ISGRAPHSC(scp))
+ return;
+
+ SC_VIDEO_LOCK(scp->sc);
+ (*scp->rndr->draw_mouse)(scp,
+ (scp->mouse_oldpos%scp->xsize + scp->xoff)
+ * scp->font_width,
+ (scp->mouse_oldpos/scp->xsize + scp->yoff)
+ * scp->font_size,
+ FALSE);
+ size = scp->xsize*scp->ysize;
+ i = scp->mouse_oldpos;
+ mark_for_update(scp, i);
+ mark_for_update(scp, i);
+#ifndef PC98
+ if (i + scp->xsize + 1 < size) {
+ mark_for_update(scp, i + scp->xsize + 1);
+ } else if (i + scp->xsize < size) {
+ mark_for_update(scp, i + scp->xsize);
+ } else if (i + 1 < size) {
+ mark_for_update(scp, i + 1);
+ }
+#endif /* PC98 */
+ scp->status &= ~MOUSE_VISIBLE;
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+int
+sc_inside_cutmark(scr_stat *scp, int pos)
+{
+ int start;
+ int end;
+
+ if (scp->mouse_cut_end < 0)
+ return FALSE;
+ if (scp->mouse_cut_start <= scp->mouse_cut_end) {
+ start = scp->mouse_cut_start;
+ end = scp->mouse_cut_end;
+ } else {
+ start = scp->mouse_cut_end;
+ end = scp->mouse_cut_start - 1;
+ }
+ return ((start <= pos) && (pos <= end));
+}
+
+void
+sc_remove_cutmarking(scr_stat *scp)
+{
+ int s;
+
+ s = spltty();
+ if (scp->mouse_cut_end >= 0) {
+ mark_for_update(scp, scp->mouse_cut_start);
+ mark_for_update(scp, scp->mouse_cut_end);
+ }
+ scp->mouse_cut_start = scp->xsize*scp->ysize;
+ scp->mouse_cut_end = -1;
+ splx(s);
+ scp->status &= ~MOUSE_CUTTING;
+}
+
+void
+sc_remove_all_cutmarkings(sc_softc_t *sc)
+{
+ scr_stat *scp;
+ int i;
+
+ /* delete cut markings in all vtys */
+ for (i = 0; i < sc->vtys; ++i) {
+ scp = SC_STAT(sc->dev[i]);
+ if (scp == NULL)
+ continue;
+ sc_remove_cutmarking(scp);
+ }
+}
+
+void
+sc_remove_all_mouse(sc_softc_t *sc)
+{
+ scr_stat *scp;
+ int i;
+
+ for (i = 0; i < sc->vtys; ++i) {
+ scp = SC_STAT(sc->dev[i]);
+ if (scp == NULL)
+ continue;
+ if (scp->status & MOUSE_VISIBLE) {
+ scp->status &= ~MOUSE_VISIBLE;
+ mark_all(scp);
+ }
+ }
+}
+
+#define IS_SPACE_CHAR(c) (((c) & 0xff) == ' ')
+
+#ifdef SC_CUT_SPACES2TABS
+#define IS_BLANK_CHAR(c) (((c) & 0xff) == ' ' || ((c) & 0xff) == '\t')
+#else
+#define IS_BLANK_CHAR(c) IS_SPACE_CHAR(c)
+#endif /* SC_CUT_SPACES2TABS */
+
+#ifdef SC_CUT_SEPCHARS
+#define IS_SEP_CHAR(c) (index(SC_CUT_SEPCHARS, (c) & 0xff) != NULL)
+#else
+#define IS_SEP_CHAR(c) IS_SPACE_CHAR(c)
+#endif /* SC_CUT_SEPCHARS */
+
+/* skip spaces to right */
+static int
+skip_spc_right(scr_stat *scp, int p)
+{
+ int c;
+ int i;
+
+ for (i = p % scp->xsize; i < scp->xsize; ++i) {
+ c = sc_vtb_getc(&scp->vtb, p);
+ if (!IS_SPACE_CHAR(c))
+ break;
+ ++p;
+ }
+ return i;
+}
+
+/* skip spaces to left */
+static int
+skip_spc_left(scr_stat *scp, int p)
+{
+ int c;
+ int i;
+
+ for (i = p-- % scp->xsize - 1; i >= 0; --i) {
+ c = sc_vtb_getc(&scp->vtb, p);
+ if (!IS_SPACE_CHAR(c))
+ break;
+ --p;
+ }
+ return i;
+}
+
+static void
+mouse_do_cut(scr_stat *scp, int from, int to)
+{
+ int blank;
+ int i;
+ int leadspaces;
+ int p;
+ int s;
+
+ for (p = from, i = blank = leadspaces = 0; p <= to; ++p) {
+ cut_buffer[i] = sc_vtb_getc(&scp->vtb, p);
+ /* Be prepared that sc_vtb_getc() can return '\0' */
+ if (cut_buffer[i] == '\0')
+ cut_buffer[i] = ' ';
+#ifdef SC_CUT_SPACES2TABS
+ if (leadspaces != -1) {
+ if (IS_SPACE_CHAR(cut_buffer[i])) {
+ leadspaces++;
+ /* Check that we are at tabstop position */
+ if ((p % scp->xsize) % 8 == 7) {
+ i -= leadspaces - 1;
+ cut_buffer[i] = '\t';
+ leadspaces = 0;
+ }
+ } else {
+ leadspaces = -1;
+ }
+ }
+#endif /* SC_CUT_SPACES2TABS */
+ /* remember the position of the last non-space char */
+ if (!IS_BLANK_CHAR(cut_buffer[i]))
+ blank = i + 1; /* the first space after the last non-space */
+ ++i;
+ /* trim trailing blank when crossing lines */
+ if ((p % scp->xsize) == (scp->xsize - 1)) {
+ cut_buffer[blank++] = '\r';
+ i = blank;
+ leadspaces = 0;
+ }
+ }
+ cut_buffer[i] = '\0';
+
+ /* remove the current marking */
+ s = spltty();
+ if (scp->mouse_cut_start <= scp->mouse_cut_end) {
+ mark_for_update(scp, scp->mouse_cut_start);
+ mark_for_update(scp, scp->mouse_cut_end);
+ } else if (scp->mouse_cut_end >= 0) {
+ mark_for_update(scp, scp->mouse_cut_end);
+ mark_for_update(scp, scp->mouse_cut_start);
+ }
+
+ /* mark the new region */
+ scp->mouse_cut_start = from;
+ scp->mouse_cut_end = to;
+ mark_for_update(scp, from);
+ mark_for_update(scp, to);
+ splx(s);
+}
+
+/* copy marked region to the cut buffer */
+static void
+mouse_cut(scr_stat *scp)
+{
+ int start;
+ int end;
+ int from;
+ int to;
+ int c;
+ int p;
+ int s;
+ int i;
+
+ start = scp->mouse_cut_start;
+ end = scp->mouse_cut_end;
+ if (scp->mouse_pos >= start) {
+ from = start;
+ to = end = scp->mouse_pos;
+ } else {
+ from = end = scp->mouse_pos;
+ to = start - 1;
+ }
+ p = to;
+ for (i = p % scp->xsize; i < scp->xsize; ++i) {
+ c = sc_vtb_getc(&scp->vtb, p);
+ if (!IS_SPACE_CHAR(c))
+ break;
+ ++p;
+ }
+ /* if there is nothing but blank chars, trim them, but mark towards eol */
+ if (i == scp->xsize) {
+ if (end >= start)
+ to = end = p - 1;
+ else
+ to = start = p;
+ }
+ mouse_do_cut(scp, from, to);
+ s = spltty();
+ scp->mouse_cut_start = start;
+ scp->mouse_cut_end = end;
+ splx(s);
+}
+
+/* a mouse button is pressed, start cut operation */
+static void
+mouse_cut_start(scr_stat *scp)
+{
+ int i;
+ int s;
+
+ if (scp->status & MOUSE_VISIBLE) {
+ sc_remove_all_cutmarkings(scp->sc);
+ if ((scp->mouse_pos == scp->mouse_cut_start) &&
+ (scp->mouse_pos == scp->mouse_cut_end)) {
+ cut_buffer[0] = '\0';
+ return;
+ } else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) {
+ /* if the pointer is on trailing blank chars, mark towards eol */
+ i = skip_spc_left(scp, scp->mouse_pos) + 1;
+ s = spltty();
+ scp->mouse_cut_start =
+ (scp->mouse_pos / scp->xsize) * scp->xsize + i;
+ scp->mouse_cut_end =
+ (scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1;
+ splx(s);
+ cut_buffer[0] = '\r';
+ } else {
+ s = spltty();
+ scp->mouse_cut_start = scp->mouse_pos;
+ scp->mouse_cut_end = scp->mouse_cut_start;
+ splx(s);
+ cut_buffer[0] = sc_vtb_getc(&scp->vtb, scp->mouse_cut_start);
+ }
+ cut_buffer[1] = '\0';
+ scp->status |= MOUSE_CUTTING;
+ mark_all(scp); /* this is probably overkill XXX */
+ }
+}
+
+/* end of cut operation */
+static void
+mouse_cut_end(scr_stat *scp)
+{
+ if (scp->status & MOUSE_VISIBLE)
+ scp->status &= ~MOUSE_CUTTING;
+}
+
+/* copy a word under the mouse pointer */
+static void
+mouse_cut_word(scr_stat *scp)
+{
+ int start;
+ int end;
+ int sol;
+ int eol;
+ int c;
+ int j;
+ int len;
+
+ /*
+ * Because we don't have locale information in the kernel,
+ * we only distinguish space char and non-space chars. Punctuation
+ * chars, symbols and other regular chars are all treated alike
+ * unless user specified SC_CUT_SEPCHARS in his kernel config file.
+ */
+ if (scp->status & MOUSE_VISIBLE) {
+ sol = (scp->mouse_pos / scp->xsize) * scp->xsize;
+ eol = sol + scp->xsize;
+ c = sc_vtb_getc(&scp->vtb, scp->mouse_pos);
+ if (IS_SEP_CHAR(c)) {
+ /* blank space */
+ for (j = scp->mouse_pos; j >= sol; --j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (!IS_SEP_CHAR(c))
+ break;
+ }
+ start = ++j;
+ for (j = scp->mouse_pos; j < eol; ++j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (!IS_SEP_CHAR(c))
+ break;
+ }
+ end = j - 1;
+ } else {
+ /* non-space word */
+ for (j = scp->mouse_pos; j >= sol; --j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (IS_SEP_CHAR(c))
+ break;
+ }
+ start = ++j;
+ for (j = scp->mouse_pos; j < eol; ++j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (IS_SEP_CHAR(c))
+ break;
+ }
+ end = j - 1;
+ }
+
+ /* copy the found word */
+ mouse_do_cut(scp, start, end);
+ len = strlen(cut_buffer);
+ if (cut_buffer[len - 1] == '\r')
+ cut_buffer[len - 1] = '\0';
+ }
+}
+
+/* copy a line under the mouse pointer */
+static void
+mouse_cut_line(scr_stat *scp)
+{
+ int len;
+ int from;
+
+ if (scp->status & MOUSE_VISIBLE) {
+ from = (scp->mouse_pos / scp->xsize) * scp->xsize;
+ mouse_do_cut(scp, from, from + scp->xsize - 1);
+ len = strlen(cut_buffer);
+ if (cut_buffer[len - 1] == '\r')
+ cut_buffer[len - 1] = '\0';
+ scp->status |= MOUSE_CUTTING;
+ }
+}
+
+/* extend the marked region to the mouse pointer position */
+static void
+mouse_cut_extend(scr_stat *scp)
+{
+ int start;
+ int end;
+ int s;
+
+ if ((scp->status & MOUSE_VISIBLE) && !(scp->status & MOUSE_CUTTING)
+ && (scp->mouse_cut_end >= 0)) {
+ if (scp->mouse_cut_start <= scp->mouse_cut_end) {
+ start = scp->mouse_cut_start;
+ end = scp->mouse_cut_end;
+ } else {
+ start = scp->mouse_cut_end;
+ end = scp->mouse_cut_start - 1;
+ }
+ s = spltty();
+ if (scp->mouse_pos > end) {
+ scp->mouse_cut_start = start;
+ scp->mouse_cut_end = end;
+ } else if (scp->mouse_pos < start) {
+ scp->mouse_cut_start = end + 1;
+ scp->mouse_cut_end = start;
+ } else {
+ if (scp->mouse_pos - start > end + 1 - scp->mouse_pos) {
+ scp->mouse_cut_start = start;
+ scp->mouse_cut_end = end;
+ } else {
+ scp->mouse_cut_start = end + 1;
+ scp->mouse_cut_end = start;
+ }
+ }
+ splx(s);
+ mouse_cut(scp);
+ scp->status |= MOUSE_CUTTING;
+ }
+}
+
+/* paste cut buffer contents into the current vty */
+void
+sc_mouse_paste(scr_stat *scp)
+{
+ sc_paste(scp, cut_buffer, strlen(cut_buffer));
+}
+
+#endif /* SC_NO_CUTPASTE */
+
+int
+sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+{
+ mouse_info_t *mouse;
+ mouse_info_t buf;
+ scr_stat *cur_scp;
+ scr_stat *scp;
+ struct proc *p1;
+ int s;
+ int f;
+
+ scp = SC_STAT(tp);
+
+ switch (cmd) {
+
+ case CONS_MOUSECTL: /* control mouse arrow */
+ case OLD_CONS_MOUSECTL:
+
+ mouse = (mouse_info_t*)data;
+
+ random_harvest(mouse, sizeof(mouse_info_t), 2, 0, RANDOM_MOUSE);
+
+ if (cmd == OLD_CONS_MOUSECTL) {
+ static u_char swapb[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
+ old_mouse_info_t *old_mouse = (old_mouse_info_t *)data;
+
+ mouse = &buf;
+ mouse->operation = old_mouse->operation;
+ switch (mouse->operation) {
+ case MOUSE_MODE:
+ mouse->u.mode = old_mouse->u.mode;
+ break;
+ case MOUSE_SHOW:
+ case MOUSE_HIDE:
+ break;
+ case MOUSE_MOVEABS:
+ case MOUSE_MOVEREL:
+ case MOUSE_ACTION:
+ mouse->u.data.x = old_mouse->u.data.x;
+ mouse->u.data.y = old_mouse->u.data.y;
+ mouse->u.data.z = 0;
+ mouse->u.data.buttons = swapb[old_mouse->u.data.buttons & 0x7];
+ break;
+ case MOUSE_GETINFO:
+ old_mouse->u.data.x = scp->mouse_xpos;
+ old_mouse->u.data.y = scp->mouse_ypos;
+ old_mouse->u.data.buttons = swapb[scp->mouse_buttons & 0x7];
+ return 0;
+ default:
+ return EINVAL;
+ }
+ }
+
+ cur_scp = scp->sc->cur_scp;
+
+ switch (mouse->operation) {
+ case MOUSE_MODE:
+ if (ISSIGVALID(mouse->u.mode.signal)) {
+ scp->mouse_signal = mouse->u.mode.signal;
+ scp->mouse_proc = td->td_proc;
+ scp->mouse_pid = td->td_proc->p_pid;
+ }
+ else {
+ scp->mouse_signal = 0;
+ scp->mouse_proc = NULL;
+ scp->mouse_pid = 0;
+ }
+ return 0;
+
+ case MOUSE_SHOW:
+ s = spltty();
+ if (!(scp->sc->flags & SC_MOUSE_ENABLED)) {
+ scp->sc->flags |= SC_MOUSE_ENABLED;
+ cur_scp->status &= ~MOUSE_HIDDEN;
+ if (!ISGRAPHSC(cur_scp))
+ mark_all(cur_scp);
+ }
+ splx(s);
+ return 0;
+ /* NOTREACHED */
+
+ case MOUSE_HIDE:
+ s = spltty();
+ if (scp->sc->flags & SC_MOUSE_ENABLED) {
+ scp->sc->flags &= ~SC_MOUSE_ENABLED;
+ sc_remove_all_mouse(scp->sc);
+ }
+ splx(s);
+ return 0;
+ /* NOTREACHED */
+
+ case MOUSE_MOVEABS:
+ s = spltty();
+ scp->mouse_xpos = mouse->u.data.x;
+ scp->mouse_ypos = mouse->u.data.y;
+ set_mouse_pos(scp);
+ splx(s);
+ break;
+
+ case MOUSE_MOVEREL:
+ s = spltty();
+ scp->mouse_xpos += mouse->u.data.x;
+ scp->mouse_ypos += mouse->u.data.y;
+ set_mouse_pos(scp);
+ splx(s);
+ break;
+
+ case MOUSE_GETINFO:
+ mouse->u.data.x = scp->mouse_xpos;
+ mouse->u.data.y = scp->mouse_ypos;
+ mouse->u.data.z = 0;
+ mouse->u.data.buttons = scp->mouse_buttons;
+ return 0;
+
+ case MOUSE_ACTION:
+ case MOUSE_MOTION_EVENT:
+ /* send out mouse event on /dev/sysmouse */
+#if 0
+ /* this should maybe only be settable from /dev/consolectl SOS */
+ if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
+ return ENOTTY;
+#endif
+ s = spltty();
+ if (mouse->u.data.x != 0 || mouse->u.data.y != 0) {
+ cur_scp->mouse_xpos += mouse->u.data.x;
+ cur_scp->mouse_ypos += mouse->u.data.y;
+ set_mouse_pos(cur_scp);
+ }
+ f = 0;
+ if (mouse->operation == MOUSE_ACTION) {
+ f = cur_scp->mouse_buttons ^ mouse->u.data.buttons;
+ cur_scp->mouse_buttons = mouse->u.data.buttons;
+ }
+ splx(s);
+
+ if (sysmouse_event(mouse) == 0)
+ return 0;
+
+ /*
+ * If any buttons are down or the mouse has moved a lot,
+ * stop the screen saver.
+ */
+ if (((mouse->operation == MOUSE_ACTION) && mouse->u.data.buttons)
+ || (mouse->u.data.x*mouse->u.data.x
+ + mouse->u.data.y*mouse->u.data.y
+ >= SC_WAKEUP_DELTA*SC_WAKEUP_DELTA)) {
+ sc_touch_scrn_saver();
+ }
+
+ cur_scp->status &= ~MOUSE_HIDDEN;
+
+ if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
+ /* has controlling process died? */
+ if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))) {
+ cur_scp->mouse_signal = 0;
+ cur_scp->mouse_proc = NULL;
+ cur_scp->mouse_pid = 0;
+ if (p1)
+ PROC_UNLOCK(p1);
+ } else {
+ psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
+ PROC_UNLOCK(cur_scp->mouse_proc);
+ break;
+ }
+ }
+
+#ifndef SC_NO_CUTPASTE
+ if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
+ break;
+
+ if ((mouse->operation == MOUSE_ACTION) && f) {
+ /* process button presses */
+ if (cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN)
+ mouse_cut_start(cur_scp);
+ else
+ mouse_cut_end(cur_scp);
+ if (cur_scp->mouse_buttons & MOUSE_BUTTON2DOWN ||
+ cur_scp->mouse_buttons & MOUSE_BUTTON3DOWN)
+ sc_mouse_paste(cur_scp);
+ }
+#endif /* SC_NO_CUTPASTE */
+ break;
+
+ case MOUSE_BUTTON_EVENT:
+ if ((mouse->u.event.id & MOUSE_BUTTONS) == 0)
+ return EINVAL;
+ if (mouse->u.event.value < 0)
+ return EINVAL;
+#if 0
+ /* this should maybe only be settable from /dev/consolectl SOS */
+ if (SC_VTY(tp->t_dev) != SC_CONSOLECTL)
+ return ENOTTY;
+#endif
+ if (mouse->u.event.value > 0)
+ cur_scp->mouse_buttons |= mouse->u.event.id;
+ else
+ cur_scp->mouse_buttons &= ~mouse->u.event.id;
+
+ if (sysmouse_event(mouse) == 0)
+ return 0;
+
+ /* if a button is held down, stop the screen saver */
+ if (mouse->u.event.value > 0)
+ sc_touch_scrn_saver();
+
+ cur_scp->status &= ~MOUSE_HIDDEN;
+
+ if (cur_scp->mouse_signal && cur_scp->mouse_proc) {
+ if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))){
+ cur_scp->mouse_signal = 0;
+ cur_scp->mouse_proc = NULL;
+ cur_scp->mouse_pid = 0;
+ if (p1)
+ PROC_UNLOCK(p1);
+ } else {
+ psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
+ PROC_UNLOCK(cur_scp->mouse_proc);
+ break;
+ }
+ }
+
+#ifndef SC_NO_CUTPASTE
+ if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
+ break;
+
+ switch (mouse->u.event.id) {
+ case MOUSE_BUTTON1DOWN:
+ switch (mouse->u.event.value % 4) {
+ case 0: /* up */
+ mouse_cut_end(cur_scp);
+ break;
+ case 1: /* single click: start cut operation */
+ mouse_cut_start(cur_scp);
+ break;
+ case 2: /* double click: cut a word */
+ mouse_cut_word(cur_scp);
+ mouse_cut_end(cur_scp);
+ break;
+ case 3: /* triple click: cut a line */
+ mouse_cut_line(cur_scp);
+ mouse_cut_end(cur_scp);
+ break;
+ }
+ break;
+ case SC_MOUSE_PASTEBUTTON:
+ switch (mouse->u.event.value) {
+ case 0: /* up */
+ break;
+ default:
+ sc_mouse_paste(cur_scp);
+ break;
+ }
+ break;
+ case SC_MOUSE_EXTENDBUTTON:
+ switch (mouse->u.event.value) {
+ case 0: /* up */
+ if (!(cur_scp->mouse_buttons & MOUSE_BUTTON1DOWN))
+ mouse_cut_end(cur_scp);
+ break;
+ default:
+ mouse_cut_extend(cur_scp);
+ break;
+ }
+ break;
+ }
+#endif /* SC_NO_CUTPASTE */
+ break;
+
+ case MOUSE_MOUSECHAR:
+ if (mouse->u.mouse_char < 0) {
+ mouse->u.mouse_char = scp->sc->mouse_char;
+ } else {
+ if (mouse->u.mouse_char > UCHAR_MAX - 3)
+ return EINVAL;
+ s = spltty();
+ sc_remove_all_mouse(scp->sc);
+#ifndef SC_NO_FONT_LOADING
+ if (ISTEXTSC(cur_scp) && (cur_scp->font != NULL))
+ sc_load_font(cur_scp, 0, cur_scp->font_size,
+ cur_scp->font_width,
+ cur_scp->font + cur_scp->font_size
+ * cur_scp->sc->mouse_char,
+ cur_scp->sc->mouse_char, 4);
+#endif
+ scp->sc->mouse_char = mouse->u.mouse_char;
+ splx(s);
+ }
+ break;
+
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+ }
+
+ return ENOIOCTL;
+}
+
+#endif /* SC_NO_SYSMOUSE */
diff --git a/sys/dev/syscons/scterm-teken.c b/sys/dev/syscons/scterm-teken.c
new file mode 100644
index 000000000000..491f82ab3c2b
--- /dev/null
+++ b/sys/dev/syscons/scterm-teken.c
@@ -0,0 +1,520 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/consio.h>
+
+#if defined(__sparc64__) || defined(__powerpc__)
+#include <machine/sc_machdep.h>
+#else
+#include <machine/pc/display.h>
+#endif
+
+#include <dev/syscons/syscons.h>
+
+#include <dev/syscons/teken/teken.h>
+
+static void scteken_revattr(unsigned char, teken_attr_t *);
+static unsigned int scteken_attr(const teken_attr_t *);
+
+static sc_term_init_t scteken_init;
+static sc_term_term_t scteken_term;
+static sc_term_puts_t scteken_puts;
+static sc_term_ioctl_t scteken_ioctl;
+static sc_term_default_attr_t scteken_default_attr;
+static sc_term_clear_t scteken_clear;
+static sc_term_input_t scteken_input;
+static void scteken_nop(void);
+
+typedef struct {
+ teken_t ts_teken;
+ int ts_busy;
+} teken_stat;
+
+static teken_stat reserved_teken_stat;
+
+static sc_term_sw_t sc_term_scteken = {
+ { NULL, NULL },
+ "scteken", /* emulator name */
+ "teken terminal", /* description */
+ "*", /* matching renderer */
+ sizeof(teken_stat), /* softc size */
+ 0,
+ scteken_init,
+ scteken_term,
+ scteken_puts,
+ scteken_ioctl,
+ (sc_term_reset_t *)scteken_nop,
+ scteken_default_attr,
+ scteken_clear,
+ (sc_term_notify_t *)scteken_nop,
+ scteken_input,
+};
+
+SCTERM_MODULE(scteken, sc_term_scteken);
+
+static tf_bell_t scteken_bell;
+static tf_cursor_t scteken_cursor;
+static tf_putchar_t scteken_putchar;
+static tf_fill_t scteken_fill;
+static tf_copy_t scteken_copy;
+static tf_param_t scteken_param;
+static tf_respond_t scteken_respond;
+
+static const teken_funcs_t scteken_funcs = {
+ .tf_bell = scteken_bell,
+ .tf_cursor = scteken_cursor,
+ .tf_putchar = scteken_putchar,
+ .tf_fill = scteken_fill,
+ .tf_copy = scteken_copy,
+ .tf_param = scteken_param,
+ .tf_respond = scteken_respond,
+};
+
+static int
+scteken_init(scr_stat *scp, void **softc, int code)
+{
+ teken_stat *ts;
+ teken_pos_t tp;
+
+ if (*softc == NULL) {
+ if (reserved_teken_stat.ts_busy)
+ return (EINVAL);
+ *softc = &reserved_teken_stat;
+ }
+ ts = *softc;
+
+ switch (code) {
+ case SC_TE_COLD_INIT:
+ ++sc_term_scteken.te_refcount;
+ ts->ts_busy = 1;
+ /* FALLTHROUGH */
+ case SC_TE_WARM_INIT:
+ teken_init(&ts->ts_teken, &scteken_funcs, scp);
+
+ tp.tp_row = scp->ysize;
+ tp.tp_col = scp->xsize;
+ teken_set_winsize(&ts->ts_teken, &tp);
+
+ tp.tp_row = scp->cursor_pos / scp->xsize;
+ tp.tp_col = scp->cursor_pos % scp->xsize;
+ teken_set_cursor(&ts->ts_teken, &tp);
+ break;
+ }
+
+ return (0);
+}
+
+static int
+scteken_term(scr_stat *scp, void **softc)
+{
+
+ if (*softc == &reserved_teken_stat) {
+ *softc = NULL;
+ reserved_teken_stat.ts_busy = 0;
+ }
+ --sc_term_scteken.te_refcount;
+
+ return (0);
+}
+
+static void
+scteken_puts(scr_stat *scp, u_char *buf, int len, int kernel)
+{
+ teken_stat *ts = scp->ts;
+ teken_attr_t backup, kattr;
+
+ scp->sc->write_in_progress++;
+ if (kernel) {
+ /* Use special colors for kernel messages. */
+ backup = *teken_get_curattr(&ts->ts_teken);
+ scteken_revattr(SC_KERNEL_CONS_ATTR, &kattr);
+ teken_set_curattr(&ts->ts_teken, &kattr);
+ teken_input(&ts->ts_teken, buf, len);
+ teken_set_curattr(&ts->ts_teken, &backup);
+ } else {
+ /* Print user messages with regular colors. */
+ teken_input(&ts->ts_teken, buf, len);
+ }
+ scp->sc->write_in_progress--;
+}
+
+static int
+scteken_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td)
+{
+ teken_stat *ts = scp->ts;
+ vid_info_t *vi;
+ unsigned int attr;
+
+ switch (cmd) {
+ case GIO_ATTR: /* get current attributes */
+ *(int*)data =
+ scteken_attr(teken_get_curattr(&ts->ts_teken));
+ return (0);
+ case CONS_GETINFO: /* get current (virtual) console info */
+ vi = (vid_info_t *)data;
+ if (vi->size != sizeof(struct vid_info))
+ return EINVAL;
+
+ attr = scteken_attr(teken_get_defattr(&ts->ts_teken));
+ vi->mv_norm.fore = attr & 0x0f;
+ vi->mv_norm.back = (attr >> 4) & 0x0f;
+ vi->mv_rev.fore = vi->mv_norm.back;
+ vi->mv_rev.back = vi->mv_norm.fore;
+ /*
+ * The other fields are filled by the upper routine. XXX
+ */
+ return (ENOIOCTL);
+ }
+
+ return (ENOIOCTL);
+}
+
+static void
+scteken_default_attr(scr_stat *scp, int color, int rev_color)
+{
+ teken_stat *ts = scp->ts;
+ teken_attr_t ta;
+
+ scteken_revattr(color, &ta);
+ teken_set_defattr(&ts->ts_teken, &ta);
+}
+
+static void
+scteken_clear(scr_stat *scp)
+{
+
+ sc_move_cursor(scp, 0, 0);
+ sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
+ mark_all(scp);
+}
+
+static int
+scteken_input(scr_stat *scp, int c, struct tty *tp)
+{
+
+ return FALSE;
+}
+
+static void
+scteken_nop(void)
+{
+
+}
+
+/*
+ * libteken routines.
+ */
+
+static const unsigned char fgcolors_normal[TC_NCOLORS] = {
+ FG_BLACK, FG_RED, FG_GREEN, FG_BROWN,
+ FG_BLUE, FG_MAGENTA, FG_CYAN, FG_LIGHTGREY,
+};
+
+static const unsigned char fgcolors_bold[TC_NCOLORS] = {
+ FG_DARKGREY, FG_LIGHTRED, FG_LIGHTGREEN, FG_YELLOW,
+ FG_LIGHTBLUE, FG_LIGHTMAGENTA, FG_LIGHTCYAN, FG_WHITE,
+};
+
+static const unsigned char bgcolors[TC_NCOLORS] = {
+ BG_BLACK, BG_RED, BG_GREEN, BG_BROWN,
+ BG_BLUE, BG_MAGENTA, BG_CYAN, BG_LIGHTGREY,
+};
+
+static void
+scteken_revattr(unsigned char color, teken_attr_t *a)
+{
+ teken_color_t fg, bg;
+
+ /*
+ * XXX: Reverse conversion of syscons to teken attributes. Not
+ * realiable. Maybe we should turn it into a 1:1 mapping one of
+ * these days?
+ */
+
+ a->ta_format = 0;
+ a->ta_fgcolor = TC_WHITE;
+ a->ta_bgcolor = TC_BLACK;
+
+#ifdef FG_BLINK
+ if (color & FG_BLINK) {
+ a->ta_format |= TF_BLINK;
+ color &= ~FG_BLINK;
+ }
+#endif /* FG_BLINK */
+
+ for (fg = 0; fg < TC_NCOLORS; fg++) {
+ for (bg = 0; bg < TC_NCOLORS; bg++) {
+ if ((fgcolors_normal[fg] | bgcolors[bg]) == color) {
+ a->ta_fgcolor = fg;
+ a->ta_bgcolor = bg;
+ return;
+ }
+
+ if ((fgcolors_bold[fg] | bgcolors[bg]) == color) {
+ a->ta_fgcolor = fg;
+ a->ta_bgcolor = bg;
+ a->ta_format |= TF_BOLD;
+ return;
+ }
+ }
+ }
+}
+
+static unsigned int
+scteken_attr(const teken_attr_t *a)
+{
+ unsigned int attr = 0;
+
+ if (a->ta_format & TF_BOLD)
+ attr |= fgcolors_bold[a->ta_fgcolor];
+ else
+ attr |= fgcolors_normal[a->ta_fgcolor];
+ attr |= bgcolors[a->ta_bgcolor];
+
+#ifdef FG_UNDERLINE
+ if (a->ta_format & TF_UNDERLINE)
+ attr |= FG_UNDERLINE;
+#endif /* FG_UNDERLINE */
+#ifdef FG_BLINK
+ if (a->ta_format & TF_BLINK)
+ attr |= FG_BLINK;
+#endif /* FG_BLINK */
+
+ return (attr);
+}
+
+static void
+scteken_bell(void *arg)
+{
+ scr_stat *scp = arg;
+
+ sc_bell(scp, scp->bell_pitch, scp->bell_duration);
+}
+
+static void
+scteken_cursor(void *arg, const teken_pos_t *p)
+{
+ scr_stat *scp = arg;
+
+ sc_move_cursor(scp, p->tp_col, p->tp_row);
+}
+
+static void
+scteken_putchar(void *arg, const teken_pos_t *tp, teken_char_t c,
+ const teken_attr_t *a)
+{
+ scr_stat *scp = arg;
+ u_char *map;
+ u_char ch;
+ vm_offset_t p;
+ int cursor, attr;
+
+#ifdef TEKEN_UTF8
+ if (c >= 0x80) {
+ /* XXX: Don't display UTF-8 yet. */
+ attr = (FG_YELLOW|BG_RED) << 8;
+ ch = '?';
+ } else
+#endif /* TEKEN_UTF8 */
+ {
+ attr = scteken_attr(a) << 8;
+ ch = c;
+ }
+
+ map = scp->sc->scr_map;
+
+ cursor = tp->tp_row * scp->xsize + tp->tp_col;
+ p = sc_vtb_pointer(&scp->vtb, cursor);
+ sc_vtb_putchar(&scp->vtb, p, map[ch], attr);
+
+ mark_for_update(scp, cursor);
+ /*
+ * XXX: Why do we need this? Only marking `cursor' should be
+ * enough. Without this line, we get artifacts.
+ */
+ mark_for_update(scp, imin(cursor + 1, scp->xsize * scp->ysize - 1));
+}
+
+static void
+scteken_fill(void *arg, const teken_rect_t *r, teken_char_t c,
+ const teken_attr_t *a)
+{
+ scr_stat *scp = arg;
+ u_char *map;
+ u_char ch;
+ unsigned int width;
+ int attr, row;
+
+#ifdef TEKEN_UTF8
+ if (c >= 0x80) {
+ /* XXX: Don't display UTF-8 yet. */
+ attr = (FG_YELLOW|BG_RED) << 8;
+ ch = '?';
+ } else
+#endif /* TEKEN_UTF8 */
+ {
+ attr = scteken_attr(a) << 8;
+ ch = c;
+ }
+
+ map = scp->sc->scr_map;
+
+ if (r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize) {
+ /* Single contiguous region to fill. */
+ sc_vtb_erase(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
+ (r->tr_end.tp_row - r->tr_begin.tp_row) * scp->xsize,
+ map[ch], attr);
+ } else {
+ /* Fill display line by line. */
+ width = r->tr_end.tp_col - r->tr_begin.tp_col;
+
+ for (row = r->tr_begin.tp_row; row < r->tr_end.tp_row; row++) {
+ sc_vtb_erase(&scp->vtb, r->tr_begin.tp_row *
+ scp->xsize + r->tr_begin.tp_col,
+ width, map[ch], attr);
+ }
+ }
+
+ /* Mark begin and end positions to be refreshed. */
+ mark_for_update(scp,
+ r->tr_begin.tp_row * scp->xsize + r->tr_begin.tp_col);
+ mark_for_update(scp,
+ (r->tr_end.tp_row - 1) * scp->xsize + (r->tr_end.tp_col - 1));
+ sc_remove_cutmarking(scp);
+}
+
+static void
+scteken_copy(void *arg, const teken_rect_t *r, const teken_pos_t *p)
+{
+ scr_stat *scp = arg;
+ unsigned int width;
+ int src, dst, end;
+
+#ifndef SC_NO_HISTORY
+ /*
+ * We count a line of input as history if we perform a copy of
+ * one whole line upward. In other words: if a line of text gets
+ * overwritten by a rectangle that's right below it.
+ */
+ if (scp->history != NULL &&
+ r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize &&
+ r->tr_begin.tp_row == p->tp_row + 1) {
+ sc_hist_save_one_line(scp, p->tp_row);
+ }
+#endif
+
+ if (r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize) {
+ /* Single contiguous region to copy. */
+ sc_vtb_move(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
+ p->tp_row * scp->xsize,
+ (r->tr_end.tp_row - r->tr_begin.tp_row) * scp->xsize);
+ } else {
+ /* Copy line by line. */
+ width = r->tr_end.tp_col - r->tr_begin.tp_col;
+
+ if (p->tp_row < r->tr_begin.tp_row) {
+ /* Copy from top to bottom. */
+ src = r->tr_begin.tp_row * scp->xsize +
+ r->tr_begin.tp_col;
+ end = r->tr_end.tp_row * scp->xsize +
+ r->tr_end.tp_col;
+ dst = p->tp_row * scp->xsize + p->tp_col;
+
+ while (src < end) {
+ sc_vtb_move(&scp->vtb, src, dst, width);
+
+ src += scp->xsize;
+ dst += scp->xsize;
+ }
+ } else {
+ /* Copy from bottom to top. */
+ src = (r->tr_end.tp_row - 1) * scp->xsize +
+ r->tr_begin.tp_col;
+ end = r->tr_begin.tp_row * scp->xsize +
+ r->tr_begin.tp_col;
+ dst = (p->tp_row + r->tr_end.tp_row -
+ r->tr_begin.tp_row - 1) * scp->xsize + p->tp_col;
+
+ while (src >= end) {
+ sc_vtb_move(&scp->vtb, src, dst, width);
+
+ src -= scp->xsize;
+ dst -= scp->xsize;
+ }
+ }
+ }
+
+ /* Mark begin and end positions to be refreshed. */
+ mark_for_update(scp,
+ p->tp_row * scp->xsize + p->tp_col);
+ mark_for_update(scp,
+ (p->tp_row + r->tr_end.tp_row - r->tr_begin.tp_row - 1) *
+ scp->xsize +
+ (p->tp_col + r->tr_end.tp_col - r->tr_begin.tp_col - 1));
+ sc_remove_cutmarking(scp);
+}
+
+static void
+scteken_param(void *arg, int cmd, int value)
+{
+ scr_stat *scp = arg;
+
+ switch (cmd) {
+ case TP_SHOWCURSOR:
+ if (value) {
+ sc_change_cursor_shape(scp,
+ CONS_RESET_CURSOR|CONS_LOCAL_CURSOR, -1, -1);
+ } else {
+ sc_change_cursor_shape(scp,
+ CONS_HIDDEN_CURSOR|CONS_LOCAL_CURSOR, -1, -1);
+ }
+ break;
+ case TP_SWITCHVT:
+ sc_switch_scr(scp->sc, value);
+ break;
+ }
+}
+
+static void
+scteken_respond(void *arg, const void *buf, size_t len)
+{
+ scr_stat *scp = arg;
+
+ sc_respond(scp, buf, len);
+}
diff --git a/sys/dev/syscons/scterm.c b/sys/dev/syscons/scterm.c
new file mode 100644
index 000000000000..f0f56b5475a6
--- /dev/null
+++ b/sys/dev/syscons/scterm.c
@@ -0,0 +1,126 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/consio.h>
+
+#include <dev/syscons/syscons.h>
+
+SET_DECLARE(scterm_set, sc_term_sw_t);
+
+/* exported subroutines */
+
+void
+sc_move_cursor(scr_stat *scp, int x, int y)
+{
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+ if (x >= scp->xsize)
+ x = scp->xsize - 1;
+ if (y >= scp->ysize)
+ y = scp->ysize - 1;
+ scp->xpos = x;
+ scp->ypos = y;
+ scp->cursor_pos = scp->ypos*scp->xsize + scp->xpos;
+}
+
+void
+sc_clear_screen(scr_stat *scp)
+{
+ (*scp->tsw->te_clear)(scp);
+ scp->cursor_oldpos = scp->cursor_pos;
+ sc_remove_cutmarking(scp);
+}
+
+/* terminal emulator manager routines */
+
+static LIST_HEAD(, sc_term_sw) sc_term_list =
+ LIST_HEAD_INITIALIZER(sc_term_list);
+
+int
+sc_term_add(sc_term_sw_t *sw)
+{
+ LIST_INSERT_HEAD(&sc_term_list, sw, link);
+ return 0;
+}
+
+int
+sc_term_remove(sc_term_sw_t *sw)
+{
+ LIST_REMOVE(sw, link);
+ return 0;
+}
+
+sc_term_sw_t
+*sc_term_match(char *name)
+{
+ sc_term_sw_t **list;
+ sc_term_sw_t *p;
+
+ if (!LIST_EMPTY(&sc_term_list)) {
+ LIST_FOREACH(p, &sc_term_list, link) {
+ if ((strcmp(name, p->te_name) == 0)
+ || (strcmp(name, "*") == 0)) {
+ return p;
+ }
+ }
+ } else {
+ SET_FOREACH(list, scterm_set) {
+ p = *list;
+ if ((strcmp(name, p->te_name) == 0)
+ || (strcmp(name, "*") == 0)) {
+ return p;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+sc_term_sw_t
+*sc_term_match_by_number(int index)
+{
+ sc_term_sw_t *p;
+
+ if (index <= 0)
+ return NULL;
+ LIST_FOREACH(p, &sc_term_list, link) {
+ if (--index <= 0)
+ return p;
+ }
+
+ return NULL;
+}
diff --git a/sys/dev/syscons/scvesactl.c b/sys/dev/syscons/scvesactl.c
new file mode 100644
index 000000000000..9a2c253869c8
--- /dev/null
+++ b/sys/dev/syscons/scvesactl.c
@@ -0,0 +1,147 @@
+/*-
+ * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sascha Wildner <saw@online.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_vga.h"
+
+#ifndef VGA_NO_MODE_CHANGE
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/fbio.h>
+#include <sys/consio.h>
+
+#include <machine/pc/vesa.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/syscons/syscons.h>
+
+static tsw_ioctl_t *prev_user_ioctl;
+
+static int
+vesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+{
+ scr_stat *scp;
+ int mode;
+
+ scp = SC_STAT(tp);
+
+ switch (cmd) {
+
+ /* generic text modes */
+ case SW_TEXT_132x25: case SW_TEXT_132x30:
+ case SW_TEXT_132x43: case SW_TEXT_132x50:
+ case SW_TEXT_132x60:
+ if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
+
+ /* text modes */
+ case SW_VESA_C80x60:
+ case SW_VESA_C132x25:
+ case SW_VESA_C132x43:
+ case SW_VESA_C132x50:
+ case SW_VESA_C132x60:
+ if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ mode = (cmd & 0xff) + M_VESA_BASE;
+ return sc_set_text_mode(scp, tp, mode, 0, 0, 0, 0);
+
+ /* graphics modes */
+ case SW_VESA_32K_320: case SW_VESA_64K_320:
+ case SW_VESA_FULL_320:
+
+ case SW_VESA_CG640x400:
+
+ case SW_VESA_CG640x480:
+ case SW_VESA_32K_640: case SW_VESA_64K_640:
+ case SW_VESA_FULL_640:
+
+ case SW_VESA_800x600: case SW_VESA_CG800x600:
+ case SW_VESA_32K_800: case SW_VESA_64K_800:
+ case SW_VESA_FULL_800:
+
+ case SW_VESA_1024x768: case SW_VESA_CG1024x768:
+ case SW_VESA_32K_1024: case SW_VESA_64K_1024:
+ case SW_VESA_FULL_1024:
+
+ case SW_VESA_1280x1024: case SW_VESA_CG1280x1024:
+ case SW_VESA_32K_1280: case SW_VESA_64K_1280:
+ case SW_VESA_FULL_1280:
+ if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ mode = (cmd & 0xff) + M_VESA_BASE;
+ return sc_set_graphics_mode(scp, tp, mode);
+ default:
+ if (IOCGROUP(cmd) == 'V') {
+ if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+
+ mode = (cmd & 0xff) + M_VESA_BASE;
+
+ if (((cmd & IOC_DIRMASK) == IOC_VOID) &&
+ (mode > M_VESA_FULL_1280) &&
+ (mode < M_VESA_MODE_MAX))
+ return sc_set_graphics_mode(scp, tp, mode);
+ }
+ }
+
+ if (prev_user_ioctl)
+ return (*prev_user_ioctl)(tp, cmd, data, td);
+ else
+ return ENOIOCTL;
+}
+
+int
+vesa_load_ioctl(void)
+{
+ if (prev_user_ioctl)
+ return EBUSY;
+ prev_user_ioctl = sc_user_ioctl;
+ sc_user_ioctl = vesa_ioctl;
+ return 0;
+}
+
+int
+vesa_unload_ioctl(void)
+{
+ if (sc_user_ioctl != vesa_ioctl)
+ return EBUSY;
+ sc_user_ioctl = prev_user_ioctl;
+ prev_user_ioctl = NULL;
+ return 0;
+}
+
+#endif /* VGA_NO_MODE_CHANGE */
diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c
new file mode 100644
index 000000000000..1ab41d2e5e4d
--- /dev/null
+++ b/sys/dev/syscons/scvgarndr.c
@@ -0,0 +1,1251 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sascha Wildner <saw@online.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+#include "opt_vga.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/fbio.h>
+#include <sys/consio.h>
+
+#include <machine/bus.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/vgareg.h>
+#include <dev/syscons/syscons.h>
+
+#include <isa/isareg.h>
+
+#ifndef SC_RENDER_DEBUG
+#define SC_RENDER_DEBUG 0
+#endif
+
+static vr_clear_t vga_txtclear;
+static vr_draw_border_t vga_txtborder;
+static vr_draw_t vga_txtdraw;
+static vr_set_cursor_t vga_txtcursor_shape;
+static vr_draw_cursor_t vga_txtcursor;
+static vr_blink_cursor_t vga_txtblink;
+#ifndef SC_NO_CUTPASTE
+static vr_draw_mouse_t vga_txtmouse;
+#else
+#define vga_txtmouse (vr_draw_mouse_t *)vga_nop
+#endif
+
+#ifdef SC_PIXEL_MODE
+static vr_init_t vga_rndrinit;
+static vr_clear_t vga_pxlclear_direct;
+static vr_clear_t vga_pxlclear_planar;
+static vr_draw_border_t vga_pxlborder_direct;
+static vr_draw_border_t vga_pxlborder_planar;
+static vr_draw_t vga_egadraw;
+static vr_draw_t vga_vgadraw_direct;
+static vr_draw_t vga_vgadraw_planar;
+static vr_set_cursor_t vga_pxlcursor_shape;
+static vr_draw_cursor_t vga_pxlcursor_direct;
+static vr_draw_cursor_t vga_pxlcursor_planar;
+static vr_blink_cursor_t vga_pxlblink_direct;
+static vr_blink_cursor_t vga_pxlblink_planar;
+#ifndef SC_NO_CUTPASTE
+static vr_draw_mouse_t vga_pxlmouse_direct;
+static vr_draw_mouse_t vga_pxlmouse_planar;
+#else
+#define vga_pxlmouse_direct (vr_draw_mouse_t *)vga_nop
+#define vga_pxlmouse_planar (vr_draw_mouse_t *)vga_nop
+#endif
+#endif /* SC_PIXEL_MODE */
+
+#ifndef SC_NO_MODE_CHANGE
+static vr_draw_border_t vga_grborder;
+#endif
+
+static void vga_nop(scr_stat *scp);
+
+static sc_rndr_sw_t txtrndrsw = {
+ (vr_init_t *)vga_nop,
+ vga_txtclear,
+ vga_txtborder,
+ vga_txtdraw,
+ vga_txtcursor_shape,
+ vga_txtcursor,
+ vga_txtblink,
+ (vr_set_mouse_t *)vga_nop,
+ vga_txtmouse,
+};
+RENDERER(mda, 0, txtrndrsw, vga_set);
+RENDERER(cga, 0, txtrndrsw, vga_set);
+RENDERER(ega, 0, txtrndrsw, vga_set);
+RENDERER(vga, 0, txtrndrsw, vga_set);
+
+#ifdef SC_PIXEL_MODE
+static sc_rndr_sw_t egarndrsw = {
+ (vr_init_t *)vga_nop,
+ vga_pxlclear_planar,
+ vga_pxlborder_planar,
+ vga_egadraw,
+ vga_pxlcursor_shape,
+ vga_pxlcursor_planar,
+ vga_pxlblink_planar,
+ (vr_set_mouse_t *)vga_nop,
+ vga_pxlmouse_planar,
+};
+RENDERER(ega, PIXEL_MODE, egarndrsw, vga_set);
+
+static sc_rndr_sw_t vgarndrsw = {
+ vga_rndrinit,
+ (vr_clear_t *)vga_nop,
+ (vr_draw_border_t *)vga_nop,
+ (vr_draw_t *)vga_nop,
+ vga_pxlcursor_shape,
+ (vr_draw_cursor_t *)vga_nop,
+ (vr_blink_cursor_t *)vga_nop,
+ (vr_set_mouse_t *)vga_nop,
+ (vr_draw_mouse_t *)vga_nop,
+};
+RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set);
+#endif /* SC_PIXEL_MODE */
+
+#ifndef SC_NO_MODE_CHANGE
+static sc_rndr_sw_t grrndrsw = {
+ (vr_init_t *)vga_nop,
+ (vr_clear_t *)vga_nop,
+ vga_grborder,
+ (vr_draw_t *)vga_nop,
+ (vr_set_cursor_t *)vga_nop,
+ (vr_draw_cursor_t *)vga_nop,
+ (vr_blink_cursor_t *)vga_nop,
+ (vr_set_mouse_t *)vga_nop,
+ (vr_draw_mouse_t *)vga_nop,
+};
+RENDERER(cga, GRAPHICS_MODE, grrndrsw, vga_set);
+RENDERER(ega, GRAPHICS_MODE, grrndrsw, vga_set);
+RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set);
+#endif /* SC_NO_MODE_CHANGE */
+
+RENDERER_MODULE(vga, vga_set);
+
+#ifndef SC_NO_CUTPASTE
+#if !defined(SC_ALT_MOUSE_IMAGE) || defined(SC_PIXEL_MODE)
+static u_short mouse_and_mask[16] = {
+ 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80,
+ 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000
+};
+static u_short mouse_or_mask[16] = {
+ 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800,
+ 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000
+};
+#endif
+#endif
+
+#ifdef SC_PIXEL_MODE
+#define VIDEO_MEMORY_POS(scp, pos, x) \
+ scp->sc->adp->va_window + \
+ x * scp->xoff + \
+ scp->yoff * scp->font_size * scp->sc->adp->va_line_width + \
+ x * (pos % scp->xsize) + \
+ scp->font_size * scp->sc->adp->va_line_width * (pos / scp->xsize)
+
+#define vga_drawpxl(pos, color) \
+ switch (scp->sc->adp->va_info.vi_depth) { \
+ case 32: \
+ case 24: \
+ writel(pos, vga_palette32[color]); \
+ break; \
+ case 16: \
+ if (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)\
+ writew(pos, vga_palette15[color]); \
+ else \
+ writew(pos, vga_palette16[color]); \
+ break; \
+ case 15: \
+ writew(pos, vga_palette15[color]); \
+ break; \
+ }
+
+static uint32_t vga_palette32[16] = {
+ 0x000000, 0x0000ad, 0x00ad00, 0x00adad,
+ 0xad0000, 0xad00ad, 0xad5200, 0xadadad,
+ 0x525252, 0x5252ff, 0x52ff52, 0x52ffff,
+ 0xff5252, 0xff52ff, 0xffff52, 0xffffff
+};
+
+static uint16_t vga_palette16[16] = {
+ 0x0000, 0x0016, 0x0560, 0x0576, 0xb000, 0xb016, 0xb2a0, 0xb576,
+ 0x52aa, 0x52bf, 0x57ea, 0x57ff, 0xfaaa, 0xfabf, 0xffea, 0xffff
+};
+
+static uint16_t vga_palette15[16] = {
+ 0x0000, 0x0016, 0x02c0, 0x02d6, 0x5800, 0x5816, 0x5940, 0x5ad6,
+ 0x294a, 0x295f, 0x2bea, 0x2bff, 0x7d4a, 0x7d5f, 0x7fea, 0x7fff
+};
+
+#ifndef SC_NO_CUTPASTE
+static uint32_t mouse_buf32[256];
+static uint16_t mouse_buf16[256];
+#endif
+#endif
+
+static void
+vga_nop(scr_stat *scp)
+{
+}
+
+/* text mode renderer */
+
+static void
+vga_txtclear(scr_stat *scp, int c, int attr)
+{
+ sc_vtb_clear(&scp->scr, c, attr);
+}
+
+static void
+vga_txtborder(scr_stat *scp, int color)
+{
+ vidd_set_border(scp->sc->adp, color);
+}
+
+static void
+vga_txtdraw(scr_stat *scp, int from, int count, int flip)
+{
+ vm_offset_t p;
+ int c;
+ int a;
+
+ if (from + count > scp->xsize*scp->ysize)
+ count = scp->xsize*scp->ysize - from;
+
+ if (flip) {
+ for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) {
+ c = sc_vtb_getc(&scp->vtb, from);
+ a = sc_vtb_geta(&scp->vtb, from);
+ a = (a & 0x8800) | ((a & 0x7000) >> 4)
+ | ((a & 0x0700) << 4);
+ p = sc_vtb_putchar(&scp->scr, p, c, a);
+ }
+ } else {
+ sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count);
+ }
+}
+
+static void
+vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink)
+{
+ if (base < 0 || base >= scp->font_size)
+ return;
+ /* the caller may set height <= 0 in order to disable the cursor */
+#if 0
+ scp->curs_attr.base = base;
+ scp->curs_attr.height = height;
+#endif
+ vidd_set_hw_cursor_shape(scp->sc->adp, base, height,
+ scp->font_size, blink);
+}
+
+static void
+draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip)
+{
+ sc_softc_t *sc;
+
+ sc = scp->sc;
+ scp->cursor_saveunder_char = c;
+ scp->cursor_saveunder_attr = a;
+
+#ifndef SC_NO_FONT_LOADING
+ if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
+ unsigned char *font;
+ int h;
+ int i;
+
+ if (scp->font_size < 14) {
+ font = sc->font_8;
+ h = 8;
+ } else if (scp->font_size >= 16) {
+ font = sc->font_16;
+ h = 16;
+ } else {
+ font = sc->font_14;
+ h = 14;
+ }
+ if (scp->curs_attr.base >= h)
+ return;
+ if (flip)
+ a = (a & 0x8800)
+ | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
+ bcopy(font + c*h, font + sc->cursor_char*h, h);
+ font = font + sc->cursor_char*h;
+ for (i = imax(h - scp->curs_attr.base - scp->curs_attr.height, 0);
+ i < h - scp->curs_attr.base; ++i) {
+ font[i] ^= 0xff;
+ }
+ /* XXX */
+ vidd_load_font(sc->adp, 0, h, 8, font, sc->cursor_char, 1);
+ sc_vtb_putc(&scp->scr, at, sc->cursor_char, a);
+ } else
+#endif /* SC_NO_FONT_LOADING */
+ {
+ if ((a & 0x7000) == 0x7000) {
+ a &= 0x8f00;
+ if ((a & 0x0700) == 0)
+ a |= 0x0700;
+ } else {
+ a |= 0x7000;
+ if ((a & 0x0700) == 0x0700)
+ a &= 0xf000;
+ }
+ if (flip)
+ a = (a & 0x8800)
+ | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4);
+ sc_vtb_putc(&scp->scr, at, c, a);
+ }
+}
+
+static void
+vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ video_adapter_t *adp;
+ int cursor_attr;
+
+ if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
+ return;
+
+ adp = scp->sc->adp;
+ if (blink) {
+ scp->status |= VR_CURSOR_BLINK;
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ vidd_set_hw_cursor(adp, at%scp->xsize,
+ at/scp->xsize);
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ vidd_set_hw_cursor(adp, -1, -1);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ } else {
+ scp->status &= ~VR_CURSOR_BLINK;
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ draw_txtcharcursor(scp, at,
+ sc_vtb_getc(&scp->scr, at),
+ sc_vtb_geta(&scp->scr, at),
+ flip);
+ } else {
+ cursor_attr = scp->cursor_saveunder_attr;
+ if (flip)
+ cursor_attr = (cursor_attr & 0x8800)
+ | ((cursor_attr & 0x7000) >> 4)
+ | ((cursor_attr & 0x0700) << 4);
+ if (scp->status & VR_CURSOR_ON)
+ sc_vtb_putc(&scp->scr, at,
+ scp->cursor_saveunder_char,
+ cursor_attr);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ }
+}
+
+static void
+vga_txtblink(scr_stat *scp, int at, int flip)
+{
+}
+
+#ifndef SC_NO_CUTPASTE
+
+static void
+draw_txtmouse(scr_stat *scp, int x, int y)
+{
+#ifndef SC_ALT_MOUSE_IMAGE
+ if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) {
+ u_char font_buf[128];
+ u_short cursor[32];
+ u_char c;
+ int pos;
+ int xoffset, yoffset;
+ int crtc_addr;
+ int i;
+
+ /* prepare mousepointer char's bitmaps */
+ pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
+ bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size,
+ &font_buf[0], scp->font_size);
+ bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size,
+ &font_buf[32], scp->font_size);
+ bcopy(scp->font
+ + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size,
+ &font_buf[64], scp->font_size);
+ bcopy(scp->font
+ + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size,
+ &font_buf[96], scp->font_size);
+ for (i = 0; i < scp->font_size; ++i) {
+ cursor[i] = font_buf[i]<<8 | font_buf[i+32];
+ cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96];
+ }
+
+ /* now and-or in the mousepointer image */
+ xoffset = x%8;
+ yoffset = y%scp->font_size;
+ for (i = 0; i < 16; ++i) {
+ cursor[i + yoffset] =
+ (cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset))
+ | (mouse_or_mask[i] >> xoffset);
+ }
+ for (i = 0; i < scp->font_size; ++i) {
+ font_buf[i] = (cursor[i] & 0xff00) >> 8;
+ font_buf[i + 32] = cursor[i] & 0xff;
+ font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8;
+ font_buf[i + 96] = cursor[i + scp->font_size] & 0xff;
+ }
+
+#if 1
+ /* wait for vertical retrace to avoid jitter on some videocards */
+ crtc_addr = scp->sc->adp->va_crtc_addr;
+ while (!(inb(crtc_addr + 6) & 0x08)) /* idle */ ;
+#endif
+ c = scp->sc->mouse_char;
+ vidd_load_font(scp->sc->adp, 0, 32, 8, font_buf, c, 4);
+
+ sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos));
+ /* FIXME: may be out of range! */
+ sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2,
+ sc_vtb_geta(&scp->scr, pos + scp->xsize));
+ if (x < (scp->xsize - 1)*8) {
+ sc_vtb_putc(&scp->scr, pos + 1, c + 1,
+ sc_vtb_geta(&scp->scr, pos + 1));
+ sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3,
+ sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
+ }
+ } else
+#endif /* SC_ALT_MOUSE_IMAGE */
+ {
+ /* Red, magenta and brown are mapped to green to to keep it readable */
+ static const int col_conv[16] = {
+ 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14
+ };
+ int pos;
+ int color;
+ int a;
+
+ pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
+ a = sc_vtb_geta(&scp->scr, pos);
+ if (scp->sc->adp->va_flags & V_ADP_COLOR)
+ color = (col_conv[(a & 0xf000) >> 12] << 12)
+ | ((a & 0x0f00) | 0x0800);
+ else
+ color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4);
+ sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color);
+ }
+}
+
+static void
+remove_txtmouse(scr_stat *scp, int x, int y)
+{
+}
+
+static void
+vga_txtmouse(scr_stat *scp, int x, int y, int on)
+{
+ if (on)
+ draw_txtmouse(scp, x, y);
+ else
+ remove_txtmouse(scp, x, y);
+}
+
+#endif /* SC_NO_CUTPASTE */
+
+#ifdef SC_PIXEL_MODE
+
+/* pixel (raster text) mode renderer */
+
+static void
+vga_rndrinit(scr_stat *scp)
+{
+ if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) {
+ scp->rndr->clear = vga_pxlclear_planar;
+ scp->rndr->draw_border = vga_pxlborder_planar;
+ scp->rndr->draw = vga_vgadraw_planar;
+ scp->rndr->draw_cursor = vga_pxlcursor_planar;
+ scp->rndr->blink_cursor = vga_pxlblink_planar;
+ scp->rndr->draw_mouse = vga_pxlmouse_planar;
+ } else if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT) {
+ scp->rndr->clear = vga_pxlclear_direct;
+ scp->rndr->draw_border = vga_pxlborder_direct;
+ scp->rndr->draw = vga_vgadraw_direct;
+ scp->rndr->draw_cursor = vga_pxlcursor_direct;
+ scp->rndr->blink_cursor = vga_pxlblink_direct;
+ scp->rndr->draw_mouse = vga_pxlmouse_direct;
+ }
+}
+
+static void
+vga_pxlclear_direct(scr_stat *scp, int c, int attr)
+{
+ vm_offset_t p;
+ int line_width;
+ int pixel_size;
+ int lines;
+ int i;
+
+ line_width = scp->sc->adp->va_line_width;
+ pixel_size = scp->sc->adp->va_info.vi_pixel_size;
+ lines = scp->ysize * scp->font_size;
+ p = scp->sc->adp->va_window +
+ line_width * scp->yoff * scp->font_size +
+ scp->xoff * 8 * pixel_size;
+
+ for (i = 0; i < lines; ++i) {
+ bzero_io((void *)p, scp->xsize * 8 * pixel_size);
+ p += line_width;
+ }
+}
+
+static void
+vga_pxlclear_planar(scr_stat *scp, int c, int attr)
+{
+ vm_offset_t p;
+ int line_width;
+ int lines;
+ int i;
+
+ /* XXX: we are just filling the screen with the background color... */
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+ outw(GDCIDX, 0x0f01); /* set/reset enable */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */
+ line_width = scp->sc->adp->va_line_width;
+ lines = scp->ysize*scp->font_size;
+ p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size
+ + scp->xoff;
+ for (i = 0; i < lines; ++i) {
+ bzero_io((void *)p, scp->xsize);
+ p += line_width;
+ }
+ outw(GDCIDX, 0x0000); /* set/reset */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+}
+
+static void
+vga_pxlborder_direct(scr_stat *scp, int color)
+{
+ vm_offset_t s;
+ vm_offset_t e;
+ vm_offset_t f;
+ int line_width;
+ int pixel_size;
+ int x;
+ int y;
+ int i;
+
+ line_width = scp->sc->adp->va_line_width;
+ pixel_size = scp->sc->adp->va_info.vi_pixel_size;
+
+ if (scp->yoff > 0) {
+ s = scp->sc->adp->va_window;
+ e = s + line_width * scp->yoff * scp->font_size;
+
+ for (f = s; f < e; f += pixel_size)
+ vga_drawpxl(f, color);
+ }
+
+ y = (scp->yoff + scp->ysize) * scp->font_size;
+
+ if (scp->ypixel > y) {
+ s = scp->sc->adp->va_window + line_width * y;
+ e = s + line_width * (scp->ypixel - y);
+
+ for (f = s; f < e; f += pixel_size)
+ vga_drawpxl(f, color);
+ }
+
+ y = scp->yoff * scp->font_size;
+ x = scp->xpixel / 8 - scp->xoff - scp->xsize;
+
+ for (i = 0; i < scp->ysize * scp->font_size; ++i) {
+ if (scp->xoff > 0) {
+ s = scp->sc->adp->va_window + line_width * (y + i);
+ e = s + scp->xoff * 8 * pixel_size;
+
+ for (f = s; f < e; f += pixel_size)
+ vga_drawpxl(f, color);
+ }
+
+ if (x > 0) {
+ s = scp->sc->adp->va_window + line_width * (y + i) +
+ scp->xoff * 8 * pixel_size +
+ scp->xsize * 8 * pixel_size;
+ e = s + x * 8 * pixel_size;
+
+ for (f = s; f < e; f += pixel_size)
+ vga_drawpxl(f, color);
+ }
+ }
+}
+
+static void
+vga_pxlborder_planar(scr_stat *scp, int color)
+{
+ vm_offset_t p;
+ int line_width;
+ int x;
+ int y;
+ int i;
+
+ vidd_set_border(scp->sc->adp, color);
+
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+ outw(GDCIDX, 0x0f01); /* set/reset enable */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ outw(GDCIDX, (color << 8) | 0x00); /* set/reset */
+ line_width = scp->sc->adp->va_line_width;
+ p = scp->sc->adp->va_window;
+ if (scp->yoff > 0)
+ bzero_io((void *)p, line_width*scp->yoff*scp->font_size);
+ y = (scp->yoff + scp->ysize)*scp->font_size;
+ if (scp->ypixel > y)
+ bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y));
+ y = scp->yoff*scp->font_size;
+ x = scp->xpixel/8 - scp->xoff - scp->xsize;
+ for (i = 0; i < scp->ysize*scp->font_size; ++i) {
+ if (scp->xoff > 0)
+ bzero_io((void *)(p + line_width*(y + i)), scp->xoff);
+ if (x > 0)
+ bzero_io((void *)(p + line_width*(y + i)
+ + scp->xoff + scp->xsize), x);
+ }
+ outw(GDCIDX, 0x0000); /* set/reset */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+}
+
+static void
+vga_egadraw(scr_stat *scp, int from, int count, int flip)
+{
+ vm_offset_t d;
+ vm_offset_t e;
+ u_char *f;
+ u_short bg;
+ u_short col1, col2;
+ int line_width;
+ int i, j;
+ int a;
+ u_char c;
+
+ line_width = scp->sc->adp->va_line_width;
+
+ d = VIDEO_MEMORY_POS(scp, from, 1);
+
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+ outw(GDCIDX, 0x0f01); /* set/reset enable */
+ bg = -1;
+ if (from + count > scp->xsize*scp->ysize)
+ count = scp->xsize*scp->ysize - from;
+ for (i = from; count-- > 0; ++i) {
+ a = sc_vtb_geta(&scp->vtb, i);
+ if (flip) {
+ col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
+ col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
+ } else {
+ col1 = (a & 0x0f00);
+ col2 = (a & 0xf000) >> 4;
+ }
+ /* set background color in EGA/VGA latch */
+ if (bg != col2) {
+ bg = col2;
+ outw(GDCIDX, bg | 0x00); /* set/reset */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ writeb(d, 0);
+ c = readb(d); /* set bg color in the latch */
+ }
+ /* foreground color */
+ outw(GDCIDX, col1 | 0x00); /* set/reset */
+ e = d;
+ f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
+ for (j = 0; j < scp->font_size; ++j, ++f) {
+ outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
+ writeb(e, 0);
+ e += line_width;
+ }
+ ++d;
+ if ((i % scp->xsize) == scp->xsize - 1)
+ d += scp->xoff*2
+ + (scp->font_size - 1)*line_width;
+ }
+ outw(GDCIDX, 0x0000); /* set/reset */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+ outw(GDCIDX, 0xff08); /* bit mask */
+}
+
+static void
+vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip)
+{
+ vm_offset_t d = 0;
+ vm_offset_t e;
+ u_char *f;
+ u_short col1, col2, color;
+ int line_width, pixel_size;
+ int i, j, k;
+ int a;
+
+ line_width = scp->sc->adp->va_line_width;
+ pixel_size = scp->sc->adp->va_info.vi_pixel_size;
+
+ d = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size);
+
+ if (from + count > scp->xsize * scp->ysize)
+ count = scp->xsize * scp->ysize - from;
+
+ for (i = from; count-- > 0; ++i) {
+ a = sc_vtb_geta(&scp->vtb, i);
+
+ if (flip) {
+ col1 = (((a & 0x7000) >> 4) | (a & 0x0800)) >> 8;
+ col2 = (((a & 0x8000) >> 4) | (a & 0x0700)) >> 8;
+ } else {
+ col1 = (a & 0x0f00) >> 8;
+ col2 = (a & 0xf000) >> 12;
+ }
+
+ e = d;
+ f = &(scp->font[sc_vtb_getc(&scp->vtb, i) * scp->font_size]);
+
+ for (j = 0; j < scp->font_size; ++j, ++f) {
+ for (k = 0; k < 8; ++k) {
+ color = *f & (1 << (7 - k)) ? col1 : col2;
+ vga_drawpxl(e + pixel_size * k, color);
+ }
+
+ e += line_width;
+ }
+
+ d += 8 * pixel_size;
+
+ if ((i % scp->xsize) == scp->xsize - 1)
+ d += scp->xoff * 16 * pixel_size +
+ (scp->font_size - 1) * line_width;
+ }
+}
+
+static void
+vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip)
+{
+ vm_offset_t d;
+ vm_offset_t e;
+ u_char *f;
+ u_short bg;
+ u_short col1, col2;
+ int line_width;
+ int i, j;
+ int a;
+ u_char c;
+
+ d = VIDEO_MEMORY_POS(scp, from, 1);
+
+ line_width = scp->sc->adp->va_line_width;
+
+ outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+ outw(GDCIDX, 0x0f01); /* set/reset enable */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ bg = -1;
+ if (from + count > scp->xsize*scp->ysize)
+ count = scp->xsize*scp->ysize - from;
+ for (i = from; count-- > 0; ++i) {
+ a = sc_vtb_geta(&scp->vtb, i);
+ if (flip) {
+ col1 = ((a & 0x7000) >> 4) | (a & 0x0800);
+ col2 = ((a & 0x8000) >> 4) | (a & 0x0700);
+ } else {
+ col1 = (a & 0x0f00);
+ col2 = (a & 0xf000) >> 4;
+ }
+ /* set background color in EGA/VGA latch */
+ if (bg != col2) {
+ bg = col2;
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, bg | 0x00); /* set/reset */
+ writeb(d, 0);
+ c = readb(d); /* set bg color in the latch */
+ outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */
+ }
+ /* foreground color */
+ outw(GDCIDX, col1 | 0x00); /* set/reset */
+ e = d;
+ f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]);
+ for (j = 0; j < scp->font_size; ++j, ++f) {
+ writeb(e, *f);
+ e += line_width;
+ }
+ ++d;
+ if ((i % scp->xsize) == scp->xsize - 1)
+ d += scp->xoff*2
+ + (scp->font_size - 1)*line_width;
+ }
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0000); /* set/reset */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+}
+
+static void
+vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink)
+{
+ if (base < 0 || base >= scp->font_size)
+ return;
+ /* the caller may set height <= 0 in order to disable the cursor */
+#if 0
+ scp->curs_attr.base = base;
+ scp->curs_attr.height = height;
+#endif
+}
+
+static void
+draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip)
+{
+ vm_offset_t d = 0;
+ u_char *f;
+ int line_width, pixel_size;
+ int height;
+ int col1, col2, color;
+ int a;
+ int i, j;
+
+ line_width = scp->sc->adp->va_line_width;
+ pixel_size = scp->sc->adp->va_info.vi_pixel_size;
+
+ d = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) +
+ (scp->font_size - scp->curs_attr.base - 1) * line_width;
+
+ a = sc_vtb_geta(&scp->vtb, at);
+
+ if (flip) {
+ col1 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
+ col2 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
+ } else {
+ col1 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8;
+ col2 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8;
+ }
+
+ f = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size +
+ scp->font_size - scp->curs_attr.base - 1]);
+
+ height = imin(scp->curs_attr.height, scp->font_size);
+
+ for (i = 0; i < height; ++i, --f) {
+ for (j = 0; j < 8; ++j) {
+ color = *f & (1 << (7 - j)) ? col1 : col2;
+ vga_drawpxl(d + pixel_size * j, color);
+ }
+
+ d -= line_width;
+ }
+}
+
+static void
+draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip)
+{
+ vm_offset_t d;
+ u_char *f;
+ int line_width;
+ int height;
+ int col;
+ int a;
+ int i;
+ u_char c;
+
+ line_width = scp->sc->adp->va_line_width;
+
+ d = VIDEO_MEMORY_POS(scp, at, 1) +
+ (scp->font_size - scp->curs_attr.base - 1) * line_width;
+
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+ outw(GDCIDX, 0x0f01); /* set/reset enable */
+ /* set background color in EGA/VGA latch */
+ a = sc_vtb_geta(&scp->vtb, at);
+ if (flip)
+ col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
+ else
+ col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
+ outw(GDCIDX, col | 0x00); /* set/reset */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ writeb(d, 0);
+ c = readb(d); /* set bg color in the latch */
+ /* foreground color */
+ if (flip)
+ col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4);
+ else
+ col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00);
+ outw(GDCIDX, col | 0x00); /* set/reset */
+ f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size
+ + scp->font_size - scp->curs_attr.base - 1]);
+ height = imin(scp->curs_attr.height, scp->font_size);
+ for (i = 0; i < height; ++i, --f) {
+ outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */
+ writeb(d, 0);
+ d -= line_width;
+ }
+ outw(GDCIDX, 0x0000); /* set/reset */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+ outw(GDCIDX, 0xff08); /* bit mask */
+}
+
+static int pxlblinkrate = 0;
+
+static void
+vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
+ return;
+
+ if (on) {
+ if (!blink) {
+ scp->status |= VR_CURSOR_ON;
+ draw_pxlcursor_direct(scp, at, on, flip);
+ } else if (++pxlblinkrate & 4) {
+ pxlblinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ draw_pxlcursor_direct(scp, at,
+ scp->status & VR_CURSOR_ON,
+ flip);
+ }
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ draw_pxlcursor_direct(scp, at, on, flip);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ if (blink)
+ scp->status |= VR_CURSOR_BLINK;
+ else
+ scp->status &= ~VR_CURSOR_BLINK;
+}
+
+static void
+vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ if (scp->curs_attr.height <= 0) /* the text cursor is disabled */
+ return;
+
+ if (on) {
+ if (!blink) {
+ scp->status |= VR_CURSOR_ON;
+ draw_pxlcursor_planar(scp, at, on, flip);
+ } else if (++pxlblinkrate & 4) {
+ pxlblinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ draw_pxlcursor_planar(scp, at,
+ scp->status & VR_CURSOR_ON,
+ flip);
+ }
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ draw_pxlcursor_planar(scp, at, on, flip);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ if (blink)
+ scp->status |= VR_CURSOR_BLINK;
+ else
+ scp->status &= ~VR_CURSOR_BLINK;
+}
+
+static void
+vga_pxlblink_direct(scr_stat *scp, int at, int flip)
+{
+ if (!(scp->status & VR_CURSOR_BLINK))
+ return;
+ if (!(++pxlblinkrate & 4))
+ return;
+ pxlblinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip);
+}
+
+static void
+vga_pxlblink_planar(scr_stat *scp, int at, int flip)
+{
+ if (!(scp->status & VR_CURSOR_BLINK))
+ return;
+ if (!(++pxlblinkrate & 4))
+ return;
+ pxlblinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip);
+}
+
+#ifndef SC_NO_CUTPASTE
+
+static void
+draw_pxlmouse_planar(scr_stat *scp, int x, int y)
+{
+ vm_offset_t p;
+ int line_width;
+ int xoff, yoff;
+ int ymax;
+ u_short m;
+ int i, j;
+
+ line_width = scp->sc->adp->va_line_width;
+ xoff = (x - scp->xoff*8)%8;
+ yoff = y - (y/line_width)*line_width;
+ ymax = imin(y + 16, scp->ypixel);
+
+ outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+ outw(GDCIDX, 0x0002); /* color compare */
+ outw(GDCIDX, 0x0007); /* color don't care */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ outw(GDCIDX, 0x0803); /* data rotate/function select (and) */
+ p = scp->sc->adp->va_window + line_width*y + x/8;
+ if (x < scp->xpixel - 8) {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = ~(mouse_and_mask[j] >> xoff);
+#if defined(__i386__) || defined(__amd64__)
+ *(u_char *)p &= m >> 8;
+ *(u_char *)(p + 1) &= m;
+#else
+ writeb(p, readb(p) & (m >> 8));
+ writeb(p + 1, readb(p + 1) & (m >> 8));
+#endif
+ p += line_width;
+ }
+ } else {
+ xoff += 8;
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = ~(mouse_and_mask[j] >> xoff);
+#if defined(__i386__) || defined(__amd64__)
+ *(u_char *)p &= m;
+#else
+ writeb(p, readb(p) & (m >> 8));
+#endif
+ p += line_width;
+ }
+ }
+ outw(GDCIDX, 0x1003); /* data rotate/function select (or) */
+ p = scp->sc->adp->va_window + line_width*y + x/8;
+ if (x < scp->xpixel - 8) {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = mouse_or_mask[j] >> xoff;
+#if defined(__i386__) || defined(__amd64__)
+ *(u_char *)p &= m >> 8;
+ *(u_char *)(p + 1) &= m;
+#else
+ writeb(p, readb(p) & (m >> 8));
+ writeb(p + 1, readb(p + 1) & (m >> 8));
+#endif
+ p += line_width;
+ }
+ } else {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = mouse_or_mask[j] >> xoff;
+#if defined(__i386__) || defined(__amd64__)
+ *(u_char *)p &= m;
+#else
+ writeb(p, readb(p) & (m >> 8));
+#endif
+ p += line_width;
+ }
+ }
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+}
+
+static void
+remove_pxlmouse_planar(scr_stat *scp, int x, int y)
+{
+ vm_offset_t p;
+ int col, row;
+ int pos;
+ int line_width;
+ int ymax;
+ int i;
+
+ /* erase the mouse cursor image */
+ col = x/8 - scp->xoff;
+ row = y/scp->font_size - scp->yoff;
+ pos = row*scp->xsize + col;
+ i = (col < scp->xsize - 1) ? 2 : 1;
+ (*scp->rndr->draw)(scp, pos, i, FALSE);
+ if (row < scp->ysize - 1)
+ (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE);
+
+ /* paint border if necessary */
+ line_width = scp->sc->adp->va_line_width;
+ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
+ outw(GDCIDX, 0x0003); /* data rotate/function select */
+ outw(GDCIDX, 0x0f01); /* set/reset enable */
+ outw(GDCIDX, 0xff08); /* bit mask */
+ outw(GDCIDX, (scp->border << 8) | 0x00); /* set/reset */
+ if (row == scp->ysize - 1) {
+ i = (scp->ysize + scp->yoff)*scp->font_size;
+ ymax = imin(i + scp->font_size, scp->ypixel);
+ p = scp->sc->adp->va_window + i*line_width + scp->xoff + col;
+ if (col < scp->xsize - 1) {
+ for (; i < ymax; ++i) {
+ writeb(p, 0);
+ writeb(p + 1, 0);
+ p += line_width;
+ }
+ } else {
+ for (; i < ymax; ++i) {
+ writeb(p, 0);
+ p += line_width;
+ }
+ }
+ }
+ if ((col == scp->xsize - 1) && (scp->xoff > 0)) {
+ i = (row + scp->yoff)*scp->font_size;
+ ymax = imin(i + scp->font_size*2, scp->ypixel);
+ p = scp->sc->adp->va_window + i*line_width
+ + scp->xoff + scp->xsize;
+ for (; i < ymax; ++i) {
+ writeb(p, 0);
+ p += line_width;
+ }
+ }
+ outw(GDCIDX, 0x0000); /* set/reset */
+ outw(GDCIDX, 0x0001); /* set/reset enable */
+}
+
+static void
+vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on)
+{
+ vm_offset_t p;
+ int line_width, pixel_size;
+ int xend, yend;
+ static int x_old = 0, xend_old = 0;
+ static int y_old = 0, yend_old = 0;
+ int i, j;
+ uint32_t *u32;
+ uint16_t *u16;
+ int bpp;
+
+ if (!on)
+ return;
+
+ bpp = scp->sc->adp->va_info.vi_depth;
+
+ if ((bpp == 16) && (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5))
+ bpp = 15;
+
+ line_width = scp->sc->adp->va_line_width;
+ pixel_size = scp->sc->adp->va_info.vi_pixel_size;
+
+ xend = imin(x + 16, scp->xpixel);
+ yend = imin(y + 16, scp->ypixel);
+
+ p = scp->sc->adp->va_window + y_old * line_width + x_old * pixel_size;
+
+ for (i = 0; i < (yend_old - y_old); i++) {
+ for (j = (xend_old - x_old - 1); j >= 0; j--) {
+ switch (bpp) {
+ case 32:
+ u32 = (uint32_t*)(p + j * pixel_size);
+ writel(u32, mouse_buf32[i * 16 + j]);
+ break;
+ case 16:
+ /* FALLTHROUGH */
+ case 15:
+ u16 = (uint16_t*)(p + j * pixel_size);
+ writew(u16, mouse_buf16[i * 16 + j]);
+ break;
+ }
+ }
+
+ p += line_width;
+ }
+
+ p = scp->sc->adp->va_window + y * line_width + x * pixel_size;
+
+ for (i = 0; i < (yend - y); i++) {
+ for (j = (xend - x - 1); j >= 0; j--) {
+ switch (bpp) {
+ case 32:
+ u32 = (uint32_t*)(p + j * pixel_size);
+ mouse_buf32[i * 16 + j] = *u32;
+ if (mouse_or_mask[i] & (1 << (15 - j)))
+ writel(u32, vga_palette32[15]);
+ else if (mouse_and_mask[i] & (1 << (15 - j)))
+ writel(u32, 0);
+ break;
+ case 16:
+ u16 = (uint16_t*)(p + j * pixel_size);
+ mouse_buf16[i * 16 + j] = *u16;
+ if (mouse_or_mask[i] & (1 << (15 - j)))
+ writew(u16, vga_palette16[15]);
+ else if (mouse_and_mask[i] & (1 << (15 - j)))
+ writew(u16, 0);
+ break;
+ case 15:
+ u16 = (uint16_t*)(p + j * pixel_size);
+ mouse_buf16[i * 16 + j] = *u16;
+ if (mouse_or_mask[i] & (1 << (15 - j)))
+ writew(u16, vga_palette15[15]);
+ else if (mouse_and_mask[i] & (1 << (15 - j)))
+ writew(u16, 0);
+ break;
+ }
+ }
+
+ p += line_width;
+ }
+
+ x_old = x;
+ y_old = y;
+ xend_old = xend;
+ yend_old = yend;
+}
+
+static void
+vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on)
+{
+ if (on)
+ draw_pxlmouse_planar(scp, x, y);
+ else
+ remove_pxlmouse_planar(scp, x, y);
+}
+
+#endif /* SC_NO_CUTPASTE */
+#endif /* SC_PIXEL_MODE */
+
+#ifndef SC_NO_MODE_CHANGE
+
+/* graphics mode renderer */
+
+static void
+vga_grborder(scr_stat *scp, int color)
+{
+ vidd_set_border(scp->sc->adp, color);
+}
+
+#endif
diff --git a/sys/dev/syscons/scvidctl.c b/sys/dev/syscons/scvidctl.c
new file mode 100644
index 000000000000..045f79f25e75
--- /dev/null
+++ b/sys/dev/syscons/scvidctl.c
@@ -0,0 +1,884 @@
+/*-
+ * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sascha Wildner <saw@online.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_compat.h"
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/signalvar.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/fbio.h>
+#include <sys/consio.h>
+#include <sys/filedesc.h>
+#include <sys/lock.h>
+#include <sys/sx.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/syscons/syscons.h>
+
+SET_DECLARE(scrndr_set, const sc_renderer_t);
+
+/* for compatibility with previous versions */
+/* 3.0-RELEASE used the following structure */
+typedef struct old_video_adapter {
+ int va_index;
+ int va_type;
+ int va_flags;
+/* flag bits are the same as the -CURRENT
+#define V_ADP_COLOR (1<<0)
+#define V_ADP_MODECHANGE (1<<1)
+#define V_ADP_STATESAVE (1<<2)
+#define V_ADP_STATELOAD (1<<3)
+#define V_ADP_FONT (1<<4)
+#define V_ADP_PALETTE (1<<5)
+#define V_ADP_BORDER (1<<6)
+#define V_ADP_VESA (1<<7)
+*/
+ int va_crtc_addr;
+ u_int va_window; /* virtual address */
+ size_t va_window_size;
+ size_t va_window_gran;
+ u_int va_buffer; /* virtual address */
+ size_t va_buffer_size;
+ int va_initial_mode;
+ int va_initial_bios_mode;
+ int va_mode;
+} old_video_adapter_t;
+
+#define OLD_CONS_ADPINFO _IOWR('c', 101, old_video_adapter_t)
+
+/* 3.1-RELEASE used the following structure */
+typedef struct old_video_adapter_info {
+ int va_index;
+ int va_type;
+ char va_name[16];
+ int va_unit;
+ int va_flags;
+ int va_io_base;
+ int va_io_size;
+ int va_crtc_addr;
+ int va_mem_base;
+ int va_mem_size;
+ u_int va_window; /* virtual address */
+ size_t va_window_size;
+ size_t va_window_gran;
+ u_int va_buffer;
+ size_t va_buffer_size;
+ int va_initial_mode;
+ int va_initial_bios_mode;
+ int va_mode;
+ int va_line_width;
+} old_video_adapter_info_t;
+
+#define OLD_CONS_ADPINFO2 _IOWR('c', 101, old_video_adapter_info_t)
+
+/* 3.0-RELEASE and 3.1-RELEASE used the following structure */
+typedef struct old_video_info {
+ int vi_mode;
+ int vi_flags;
+/* flag bits are the same as the -CURRENT
+#define V_INFO_COLOR (1<<0)
+#define V_INFO_GRAPHICS (1<<1)
+#define V_INFO_LINEAR (1<<2)
+#define V_INFO_VESA (1<<3)
+*/
+ int vi_width;
+ int vi_height;
+ int vi_cwidth;
+ int vi_cheight;
+ int vi_depth;
+ int vi_planes;
+ u_int vi_window; /* physical address */
+ size_t vi_window_size;
+ size_t vi_window_gran;
+ u_int vi_buffer; /* physical address */
+ size_t vi_buffer_size;
+} old_video_info_t;
+
+#define OLD_CONS_MODEINFO _IOWR('c', 102, old_video_info_t)
+#define OLD_CONS_FINDMODE _IOWR('c', 103, old_video_info_t)
+
+int
+sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
+ int fontsize, int fontwidth)
+{
+ video_info_t info;
+ u_char *font;
+ int prev_ysize;
+ int error;
+ int s;
+
+ if (vidd_get_info(scp->sc->adp, mode, &info))
+ return ENODEV;
+
+ /* adjust argument values */
+ if (fontwidth <= 0)
+ fontwidth = info.vi_cwidth;
+ if (fontsize <= 0)
+ fontsize = info.vi_cheight;
+ if (fontsize < 14) {
+ fontsize = 8;
+#ifndef SC_NO_FONT_LOADING
+ if (!(scp->sc->fonts_loaded & FONT_8))
+ return EINVAL;
+ font = scp->sc->font_8;
+#else
+ font = NULL;
+#endif
+ } else if (fontsize >= 16) {
+ fontsize = 16;
+#ifndef SC_NO_FONT_LOADING
+ if (!(scp->sc->fonts_loaded & FONT_16))
+ return EINVAL;
+ font = scp->sc->font_16;
+#else
+ font = NULL;
+#endif
+ } else {
+ fontsize = 14;
+#ifndef SC_NO_FONT_LOADING
+ if (!(scp->sc->fonts_loaded & FONT_14))
+ return EINVAL;
+ font = scp->sc->font_14;
+#else
+ font = NULL;
+#endif
+ }
+ if ((xsize <= 0) || (xsize > info.vi_width))
+ xsize = info.vi_width;
+ if ((ysize <= 0) || (ysize > info.vi_height))
+ ysize = info.vi_height;
+
+ /* stop screen saver, etc */
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+
+ if (sc_render_match(scp, scp->sc->adp->va_name, 0) == NULL) {
+ splx(s);
+ return ENODEV;
+ }
+
+ /* set up scp */
+#ifndef SC_NO_HISTORY
+ if (scp->history != NULL)
+ sc_hist_save(scp);
+#endif
+ prev_ysize = scp->ysize;
+ /*
+ * This is a kludge to fend off scrn_update() while we
+ * muck around with scp. XXX
+ */
+ scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
+ scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE | MOUSE_VISIBLE);
+ scp->mode = mode;
+ scp->xsize = xsize;
+ scp->ysize = ysize;
+ scp->xoff = 0;
+ scp->yoff = 0;
+ scp->xpixel = scp->xsize*8;
+ scp->ypixel = scp->ysize*fontsize;
+ scp->font = font;
+ scp->font_size = fontsize;
+ scp->font_width = fontwidth;
+
+ /* allocate buffers */
+ sc_alloc_scr_buffer(scp, TRUE, TRUE);
+ sc_init_emulator(scp, NULL);
+#ifndef SC_NO_CUTPASTE
+ sc_alloc_cut_buffer(scp, FALSE);
+#endif
+#ifndef SC_NO_HISTORY
+ sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
+#endif
+ splx(s);
+
+ if (scp == scp->sc->cur_scp)
+ set_mode(scp);
+ scp->status &= ~UNKNOWN_MODE;
+
+ if (tp == NULL)
+ return 0;
+ DPRINTF(5, ("ws_*size (%d,%d), size (%d,%d)\n",
+ tp->t_winsize.ws_col, tp->t_winsize.ws_row, scp->xsize, scp->ysize));
+ if (tp->t_winsize.ws_col != scp->xsize
+ || tp->t_winsize.ws_row != scp->ysize) {
+ tp->t_winsize.ws_col = scp->xsize;
+ tp->t_winsize.ws_row = scp->ysize;
+
+ tty_signal_pgrp(tp, SIGWINCH);
+ }
+
+ return 0;
+}
+
+int
+sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
+{
+#ifdef SC_NO_MODE_CHANGE
+ return ENODEV;
+#else
+ video_info_t info;
+ int error;
+ int s;
+
+ if (vidd_get_info(scp->sc->adp, mode, &info))
+ return ENODEV;
+
+ /* stop screen saver, etc */
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+
+ if (sc_render_match(scp, scp->sc->adp->va_name, GRAPHICS_MODE) == NULL) {
+ splx(s);
+ return ENODEV;
+ }
+
+ /* set up scp */
+ scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE | MOUSE_HIDDEN);
+ scp->status &= ~(PIXEL_MODE | MOUSE_VISIBLE);
+ scp->mode = mode;
+ /*
+ * Don't change xsize and ysize; preserve the previous vty
+ * and history buffers.
+ */
+ scp->xoff = 0;
+ scp->yoff = 0;
+ scp->xpixel = info.vi_width;
+ scp->ypixel = info.vi_height;
+ scp->font = NULL;
+ scp->font_size = 0;
+#ifndef SC_NO_SYSMOUSE
+ /* move the mouse cursor at the center of the screen */
+ sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
+#endif
+ sc_init_emulator(scp, NULL);
+ splx(s);
+
+ if (scp == scp->sc->cur_scp)
+ set_mode(scp);
+ /* clear_graphics();*/
+ scp->status &= ~UNKNOWN_MODE;
+
+ if (tp == NULL)
+ return 0;
+ if (tp->t_winsize.ws_xpixel != scp->xpixel
+ || tp->t_winsize.ws_ypixel != scp->ypixel) {
+ tp->t_winsize.ws_xpixel = scp->xpixel;
+ tp->t_winsize.ws_ypixel = scp->ypixel;
+
+ tty_signal_pgrp(tp, SIGWINCH);
+ }
+
+ return 0;
+#endif /* SC_NO_MODE_CHANGE */
+}
+
+int
+sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
+ int fontsize, int fontwidth)
+{
+#ifndef SC_PIXEL_MODE
+ return ENODEV;
+#else
+ video_info_t info;
+ u_char *font;
+ int prev_ysize;
+ int error;
+ int s;
+
+ if (vidd_get_info(scp->sc->adp, scp->mode, &info))
+ return ENODEV; /* this shouldn't happen */
+
+ /* adjust argument values */
+ if (fontsize <= 0)
+ fontsize = info.vi_cheight;
+ if (fontsize < 14) {
+ fontsize = 8;
+#ifndef SC_NO_FONT_LOADING
+ if (!(scp->sc->fonts_loaded & FONT_8))
+ return EINVAL;
+ font = scp->sc->font_8;
+#else
+ font = NULL;
+#endif
+ } else if (fontsize >= 16) {
+ fontsize = 16;
+#ifndef SC_NO_FONT_LOADING
+ if (!(scp->sc->fonts_loaded & FONT_16))
+ return EINVAL;
+ font = scp->sc->font_16;
+#else
+ font = NULL;
+#endif
+ } else {
+ fontsize = 14;
+#ifndef SC_NO_FONT_LOADING
+ if (!(scp->sc->fonts_loaded & FONT_14))
+ return EINVAL;
+ font = scp->sc->font_14;
+#else
+ font = NULL;
+#endif
+ }
+ if (xsize <= 0)
+ xsize = info.vi_width/8;
+ if (ysize <= 0)
+ ysize = info.vi_height/fontsize;
+
+ if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
+ return EINVAL;
+
+ /*
+ * We currently support the following graphic modes:
+ *
+ * - 4 bpp planar modes whose memory size does not exceed 64K
+ * - 15, 16, 24 and 32 bpp linear modes
+ */
+
+ if (info.vi_mem_model == V_INFO_MM_PLANAR) {
+ if (info.vi_planes != 4)
+ return ENODEV;
+
+ /*
+ * A memory size >64K requires bank switching to access the entire
+ * screen. XXX
+ */
+
+ if (info.vi_width * info.vi_height / 8 > info.vi_window_size)
+ return ENODEV;
+ } else if (info.vi_mem_model == V_INFO_MM_DIRECT) {
+ if (!(info.vi_flags & V_INFO_LINEAR) &&
+ (info.vi_depth != 15) && (info.vi_depth != 16) &&
+ (info.vi_depth != 24) && (info.vi_depth != 32))
+ return ENODEV;
+ } else
+ return ENODEV;
+
+ /* stop screen saver, etc */
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+
+ if (sc_render_match(scp, scp->sc->adp->va_name, PIXEL_MODE) == NULL) {
+ splx(s);
+ return ENODEV;
+ }
+
+#if 0
+ if (scp->tsw)
+ (*scp->tsw->te_term)(scp, scp->ts);
+ scp->tsw = NULL;
+ scp->ts = NULL;
+#endif
+
+ /* set up scp */
+#ifndef SC_NO_HISTORY
+ if (scp->history != NULL)
+ sc_hist_save(scp);
+#endif
+ prev_ysize = scp->ysize;
+ scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
+ scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
+ scp->xsize = xsize;
+ scp->ysize = ysize;
+ scp->xoff = (scp->xpixel/8 - xsize)/2;
+ scp->yoff = (scp->ypixel/fontsize - ysize)/2;
+ scp->font = font;
+ scp->font_size = fontsize;
+ scp->font_width = fontwidth;
+
+ /* allocate buffers */
+ sc_alloc_scr_buffer(scp, TRUE, TRUE);
+ sc_init_emulator(scp, NULL);
+#ifndef SC_NO_CUTPASTE
+ sc_alloc_cut_buffer(scp, FALSE);
+#endif
+#ifndef SC_NO_HISTORY
+ sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
+#endif
+ splx(s);
+
+ if (scp == scp->sc->cur_scp) {
+ sc_set_border(scp, scp->border);
+ sc_set_cursor_image(scp);
+ }
+
+ scp->status &= ~UNKNOWN_MODE;
+
+ if (tp == NULL)
+ return 0;
+ if (tp->t_winsize.ws_col != scp->xsize
+ || tp->t_winsize.ws_row != scp->ysize) {
+ tp->t_winsize.ws_col = scp->xsize;
+ tp->t_winsize.ws_row = scp->ysize;
+ if (tp->t_pgrp != NULL) {
+ PGRP_LOCK(tp->t_pgrp);
+ pgsignal(tp->t_pgrp, SIGWINCH, 1);
+ PGRP_UNLOCK(tp->t_pgrp);
+ }
+ }
+
+ return 0;
+#endif /* SC_PIXEL_MODE */
+}
+
+#define fb_ioctl(a, c, d) \
+ (((a) == NULL) ? ENODEV : \
+ vidd_ioctl((a), (c), (caddr_t)(d)))
+
+int
+sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+{
+ scr_stat *scp;
+ video_adapter_t *adp;
+ video_info_t info;
+ video_adapter_info_t adp_info;
+ int error;
+ int s;
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ int ival;
+#endif
+
+ scp = SC_STAT(tp);
+ if (scp == NULL) /* tp == SC_MOUSE */
+ return ENOIOCTL;
+ adp = scp->sc->adp;
+ if (adp == NULL) /* shouldn't happen??? */
+ return ENODEV;
+
+ switch (cmd) {
+
+ case CONS_CURRENTADP: /* get current adapter index */
+ case FBIO_ADAPTER:
+ return fb_ioctl(adp, FBIO_ADAPTER, data);
+
+ case CONS_CURRENT: /* get current adapter type */
+ case FBIO_ADPTYPE:
+ return fb_ioctl(adp, FBIO_ADPTYPE, data);
+
+ case OLD_CONS_ADPINFO: /* adapter information (old interface) */
+ if (((old_video_adapter_t *)data)->va_index >= 0) {
+ adp = vid_get_adapter(((old_video_adapter_t *)data)->va_index);
+ if (adp == NULL)
+ return ENODEV;
+ }
+ ((old_video_adapter_t *)data)->va_index = adp->va_index;
+ ((old_video_adapter_t *)data)->va_type = adp->va_type;
+ ((old_video_adapter_t *)data)->va_flags = adp->va_flags;
+ ((old_video_adapter_t *)data)->va_crtc_addr = adp->va_crtc_addr;
+ ((old_video_adapter_t *)data)->va_window = adp->va_window;
+ ((old_video_adapter_t *)data)->va_window_size = adp->va_window_size;
+ ((old_video_adapter_t *)data)->va_window_gran = adp->va_window_gran;
+ ((old_video_adapter_t *)data)->va_buffer = adp->va_buffer;
+ ((old_video_adapter_t *)data)->va_buffer_size = adp->va_buffer_size;
+ ((old_video_adapter_t *)data)->va_mode = adp->va_mode;
+ ((old_video_adapter_t *)data)->va_initial_mode = adp->va_initial_mode;
+ ((old_video_adapter_t *)data)->va_initial_bios_mode
+ = adp->va_initial_bios_mode;
+ return 0;
+
+ case OLD_CONS_ADPINFO2: /* adapter information (yet another old I/F) */
+ adp_info.va_index = ((old_video_adapter_info_t *)data)->va_index;
+ if (adp_info.va_index >= 0) {
+ adp = vid_get_adapter(adp_info.va_index);
+ if (adp == NULL)
+ return ENODEV;
+ }
+ error = fb_ioctl(adp, FBIO_ADPINFO, &adp_info);
+ if (error == 0)
+ bcopy(&adp_info, data, sizeof(old_video_adapter_info_t));
+ return error;
+
+ case CONS_ADPINFO: /* adapter information */
+ case FBIO_ADPINFO:
+ if (((video_adapter_info_t *)data)->va_index >= 0) {
+ adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index);
+ if (adp == NULL)
+ return ENODEV;
+ }
+ return fb_ioctl(adp, FBIO_ADPINFO, data);
+
+ case CONS_GET: /* get current video mode */
+ case FBIO_GETMODE:
+ *(int *)data = scp->mode;
+ return 0;
+
+#ifndef SC_NO_MODE_CHANGE
+ case FBIO_SETMODE: /* set video mode */
+ if (!(adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ info.vi_mode = *(int *)data;
+ error = fb_ioctl(adp, FBIO_MODEINFO, &info);
+ if (error)
+ return error;
+ if (info.vi_flags & V_INFO_GRAPHICS)
+ return sc_set_graphics_mode(scp, tp, *(int *)data);
+ else
+ return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0, 0);
+#endif /* SC_NO_MODE_CHANGE */
+
+ case OLD_CONS_MODEINFO: /* get mode information (old infterface) */
+ info.vi_mode = ((old_video_info_t *)data)->vi_mode;
+ error = fb_ioctl(adp, FBIO_MODEINFO, &info);
+ if (error == 0)
+ bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t));
+ return error;
+
+ case CONS_MODEINFO: /* get mode information */
+ case FBIO_MODEINFO:
+ return fb_ioctl(adp, FBIO_MODEINFO, data);
+
+ case OLD_CONS_FINDMODE: /* find a matching video mode (old interface) */
+ bzero(&info, sizeof(info));
+ bcopy((old_video_info_t *)data, &info, sizeof(old_video_info_t));
+ error = fb_ioctl(adp, FBIO_FINDMODE, &info);
+ if (error == 0)
+ bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t));
+ return error;
+
+ case CONS_FINDMODE: /* find a matching video mode */
+ case FBIO_FINDMODE:
+ return fb_ioctl(adp, FBIO_FINDMODE, data);
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('c', 104):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case CONS_SETWINORG: /* set frame buffer window origin */
+ case FBIO_SETWINORG:
+ if (scp != scp->sc->cur_scp)
+ return ENODEV; /* XXX */
+ return fb_ioctl(adp, FBIO_SETWINORG, data);
+
+ case FBIO_GETWINORG: /* get frame buffer window origin */
+ if (scp != scp->sc->cur_scp)
+ return ENODEV; /* XXX */
+ return fb_ioctl(adp, FBIO_GETWINORG, data);
+
+ case FBIO_GETDISPSTART:
+ case FBIO_SETDISPSTART:
+ case FBIO_GETLINEWIDTH:
+ case FBIO_SETLINEWIDTH:
+ if (scp != scp->sc->cur_scp)
+ return ENODEV; /* XXX */
+ return fb_ioctl(adp, cmd, data);
+
+ case FBIO_GETPALETTE:
+ case FBIO_SETPALETTE:
+ case FBIOPUTCMAP:
+ case FBIOGETCMAP:
+ case FBIOGTYPE:
+ case FBIOGATTR:
+ case FBIOSVIDEO:
+ case FBIOGVIDEO:
+ case FBIOSCURSOR:
+ case FBIOGCURSOR:
+ case FBIOSCURPOS:
+ case FBIOGCURPOS:
+ case FBIOGCURMAX:
+ if (scp != scp->sc->cur_scp)
+ return ENODEV; /* XXX */
+ return fb_ioctl(adp, cmd, data);
+
+ case FBIO_BLANK:
+ if (scp != scp->sc->cur_scp)
+ return ENODEV; /* XXX */
+ return fb_ioctl(adp, cmd, data);
+
+#ifndef SC_NO_MODE_CHANGE
+ /* generic text modes */
+ case SW_TEXT_80x25: case SW_TEXT_80x30:
+ case SW_TEXT_80x43: case SW_TEXT_80x50:
+ case SW_TEXT_80x60:
+ /* FALLTHROUGH */
+
+ /* VGA TEXT MODES */
+ case SW_VGA_C40x25:
+ case SW_VGA_C80x25: case SW_VGA_M80x25:
+ case SW_VGA_C80x30: case SW_VGA_M80x30:
+ case SW_VGA_C80x50: case SW_VGA_M80x50:
+ case SW_VGA_C80x60: case SW_VGA_M80x60:
+ case SW_VGA_C90x25: case SW_VGA_M90x25:
+ case SW_VGA_C90x30: case SW_VGA_M90x30:
+ case SW_VGA_C90x43: case SW_VGA_M90x43:
+ case SW_VGA_C90x50: case SW_VGA_M90x50:
+ case SW_VGA_C90x60: case SW_VGA_M90x60:
+ case SW_B40x25: case SW_C40x25:
+ case SW_B80x25: case SW_C80x25:
+ case SW_ENH_B40x25: case SW_ENH_C40x25:
+ case SW_ENH_B80x25: case SW_ENH_C80x25:
+ case SW_ENH_B80x43: case SW_ENH_C80x43:
+ case SW_EGAMONO80x25:
+
+#ifdef PC98
+ /* PC98 TEXT MODES */
+ case SW_PC98_80x25:
+ case SW_PC98_80x30:
+#endif
+ if (!(adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
+
+ /* GRAPHICS MODES */
+ case SW_BG320: case SW_BG640:
+ case SW_CG320: case SW_CG320_D: case SW_CG640_E:
+ case SW_CG640x350: case SW_ENH_CG640:
+ case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320:
+ case SW_VGA_MODEX:
+#ifdef PC98
+ /* PC98 GRAPHICS MODES */
+ case SW_PC98_EGC640x400: case SW_PC98_PEGC640x400:
+ case SW_PC98_PEGC640x480:
+#endif
+ if (!(adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ return sc_set_graphics_mode(scp, tp, cmd & 0xff);
+#endif /* SC_NO_MODE_CHANGE */
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 10):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDSETMODE: /* set current mode of this (virtual) console */
+ switch (*(int *)data) {
+ case KD_TEXT: /* switch to TEXT (known) mode */
+ /*
+ * If scp->mode is of graphics modes, we don't know which
+ * text mode to switch back to...
+ */
+ if (scp->status & GRAPHICS_MODE)
+ return EINVAL;
+ /* restore fonts & palette ! */
+#if 0
+#ifndef SC_NO_FONT_LOADING
+ if (ISFONTAVAIL(adp->va_flags)
+ && !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
+ /*
+ * FONT KLUDGE
+ * Don't load fonts for now... XXX
+ */
+ if (scp->sc->fonts_loaded & FONT_8)
+ sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
+ if (scp->sc->fonts_loaded & FONT_14)
+ sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
+ if (scp->sc->fonts_loaded & FONT_16)
+ sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
+ }
+#endif /* SC_NO_FONT_LOADING */
+#endif
+
+#ifndef SC_NO_PALETTE_LOADING
+ vidd_load_palette(adp, scp->sc->palette);
+#endif
+
+#ifndef PC98
+ /* move hardware cursor out of the way */
+ vidd_set_hw_cursor(adp, -1, -1);
+#endif
+
+ /* FALLTHROUGH */
+
+ case KD_TEXT1: /* switch to TEXT (known) mode */
+ /*
+ * If scp->mode is of graphics modes, we don't know which
+ * text/pixel mode to switch back to...
+ */
+ if (scp->status & GRAPHICS_MODE)
+ return EINVAL;
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+#ifndef PC98
+ scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
+ splx(s);
+ /* no restore fonts & palette */
+ if (scp == scp->sc->cur_scp)
+ set_mode(scp);
+ sc_clear_screen(scp);
+ scp->status &= ~UNKNOWN_MODE;
+#else /* PC98 */
+ scp->status &= ~UNKNOWN_MODE;
+ /* no restore fonts & palette */
+ if (scp == scp->sc->cur_scp)
+ set_mode(scp);
+ sc_clear_screen(scp);
+ splx(s);
+#endif /* PC98 */
+ return 0;
+
+#ifdef SC_PIXEL_MODE
+ case KD_PIXEL: /* pixel (raster) display */
+ if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
+ return EINVAL;
+ if (scp->status & GRAPHICS_MODE)
+ return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
+ scp->font_size, scp->font_width);
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+ scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
+ splx(s);
+ if (scp == scp->sc->cur_scp) {
+ set_mode(scp);
+#ifndef SC_NO_PALETTE_LOADING
+ vidd_load_palette(adp, scp->sc->palette);
+#endif
+ }
+ sc_clear_screen(scp);
+ scp->status &= ~UNKNOWN_MODE;
+ return 0;
+#endif /* SC_PIXEL_MODE */
+
+ case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+ scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
+ splx(s);
+#ifdef PC98
+ if (scp == scp->sc->cur_scp)
+ set_mode(scp);
+#endif
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+ /* NOT REACHED */
+
+#ifdef SC_PIXEL_MODE
+ case KDRASTER: /* set pixel (raster) display mode */
+ if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
+ return ENODEV;
+ return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
+ ((int *)data)[2], 8);
+#endif /* SC_PIXEL_MODE */
+
+ case KDGETMODE: /* get current mode of this (virtual) console */
+ /*
+ * From the user program's point of view, KD_PIXEL is the same
+ * as KD_TEXT...
+ */
+ *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
+ return 0;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 13):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDSBORDER: /* set border color of this (virtual) console */
+ scp->border = *(int *)data;
+ if (scp == scp->sc->cur_scp)
+ sc_set_border(scp, scp->border);
+ return 0;
+ }
+
+ return ENOIOCTL;
+}
+
+static LIST_HEAD(, sc_renderer) sc_rndr_list =
+ LIST_HEAD_INITIALIZER(sc_rndr_list);
+
+int
+sc_render_add(sc_renderer_t *rndr)
+{
+ LIST_INSERT_HEAD(&sc_rndr_list, rndr, link);
+ return 0;
+}
+
+int
+sc_render_remove(sc_renderer_t *rndr)
+{
+ /*
+ LIST_REMOVE(rndr, link);
+ */
+ return EBUSY; /* XXX */
+}
+
+sc_rndr_sw_t
+*sc_render_match(scr_stat *scp, char *name, int mode)
+{
+ const sc_renderer_t **list;
+ const sc_renderer_t *p;
+
+ if (!LIST_EMPTY(&sc_rndr_list)) {
+ LIST_FOREACH(p, &sc_rndr_list, link) {
+ if ((strcmp(p->name, name) == 0)
+ && (mode == p->mode)) {
+ scp->status &=
+ ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
+ return p->rndrsw;
+ }
+ }
+ } else {
+ SET_FOREACH(list, scrndr_set) {
+ p = *list;
+ if ((strcmp(p->name, name) == 0)
+ && (mode == p->mode)) {
+ scp->status &=
+ ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
+ return p->rndrsw;
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/sys/dev/syscons/scvtb.c b/sys/dev/syscons/scvtb.c
new file mode 100644
index 000000000000..8d2b224b36dd
--- /dev/null
+++ b/sys/dev/syscons/scvtb.c
@@ -0,0 +1,324 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/fbio.h>
+#include <sys/consio.h>
+
+#include <machine/md_var.h>
+#include <machine/bus.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/syscons/syscons.h>
+
+#define vtb_wrap(vtb, at, offset) \
+ (((at) + (offset) + (vtb)->vtb_size)%(vtb)->vtb_size)
+
+void
+sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows, void *buf, int wait)
+{
+ vtb->vtb_flags = 0;
+ vtb->vtb_type = type;
+ vtb->vtb_cols = cols;
+ vtb->vtb_rows = rows;
+ vtb->vtb_size = cols*rows;
+ vtb->vtb_buffer = 0;
+ vtb->vtb_tail = 0;
+
+ switch (type) {
+ case VTB_MEMORY:
+ case VTB_RINGBUFFER:
+ if ((buf == NULL) && (cols*rows != 0)) {
+ vtb->vtb_buffer =
+ (vm_offset_t)malloc(cols*rows*sizeof(u_int16_t),
+ M_DEVBUF,
+ (wait) ? M_WAITOK : M_NOWAIT);
+ if (vtb->vtb_buffer != 0) {
+ bzero((void *)sc_vtb_pointer(vtb, 0),
+ cols*rows*sizeof(u_int16_t));
+ vtb->vtb_flags |= VTB_ALLOCED;
+ }
+ } else {
+ vtb->vtb_buffer = (vm_offset_t)buf;
+ }
+ vtb->vtb_flags |= VTB_VALID;
+ break;
+#ifndef __sparc64__
+ case VTB_FRAMEBUFFER:
+ vtb->vtb_buffer = (vm_offset_t)buf;
+ vtb->vtb_flags |= VTB_VALID;
+ break;
+#endif
+ default:
+ break;
+ }
+}
+
+void
+sc_vtb_destroy(sc_vtb_t *vtb)
+{
+ vm_offset_t p;
+
+ vtb->vtb_cols = 0;
+ vtb->vtb_rows = 0;
+ vtb->vtb_size = 0;
+ vtb->vtb_tail = 0;
+
+ p = vtb->vtb_buffer;
+ vtb->vtb_buffer = 0;
+ switch (vtb->vtb_type) {
+ case VTB_MEMORY:
+ case VTB_RINGBUFFER:
+ if ((vtb->vtb_flags & VTB_ALLOCED) && (p != 0))
+ free((void *)p, M_DEVBUF);
+ break;
+ default:
+ break;
+ }
+ vtb->vtb_flags = 0;
+ vtb->vtb_type = VTB_INVALID;
+}
+
+size_t
+sc_vtb_size(int cols, int rows)
+{
+ return (size_t)(cols*rows*sizeof(u_int16_t));
+}
+
+int
+sc_vtb_getc(sc_vtb_t *vtb, int at)
+{
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ return (readw(sc_vtb_pointer(vtb, at)) & 0x00ff);
+ else
+#endif
+ return (*(u_int16_t *)sc_vtb_pointer(vtb, at) & 0x00ff);
+}
+
+int
+sc_vtb_geta(sc_vtb_t *vtb, int at)
+{
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ return (readw(sc_vtb_pointer(vtb, at)) & 0xff00);
+ else
+#endif
+ return (*(u_int16_t *)sc_vtb_pointer(vtb, at) & 0xff00);
+}
+
+void
+sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a)
+{
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ writew(sc_vtb_pointer(vtb, at), a | c);
+ else
+#endif
+ *(u_int16_t *)sc_vtb_pointer(vtb, at) = a | c;
+}
+
+vm_offset_t
+sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a)
+{
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ writew(p, a | c);
+ else
+#endif
+ *(u_int16_t *)p = a | c;
+ return (p + sizeof(u_int16_t));
+}
+
+vm_offset_t
+sc_vtb_pointer(sc_vtb_t *vtb, int at)
+{
+ return (vtb->vtb_buffer + sizeof(u_int16_t)*(at));
+}
+
+int
+sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset)
+{
+ return ((pos + offset + vtb->vtb_size)%vtb->vtb_size);
+}
+
+void
+sc_vtb_clear(sc_vtb_t *vtb, int c, int attr)
+{
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, 0), vtb->vtb_size);
+ else
+#endif
+ fillw(attr | c, (void *)sc_vtb_pointer(vtb, 0), vtb->vtb_size);
+}
+
+void
+sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to, int count)
+{
+#ifndef __sparc64__
+ /* XXX if both are VTB_VRAMEBUFFER... */
+ if (vtb2->vtb_type == VTB_FRAMEBUFFER)
+ bcopy_toio(sc_vtb_pointer(vtb1, from),
+ sc_vtb_pointer(vtb2, to),
+ count*sizeof(u_int16_t));
+ else if (vtb1->vtb_type == VTB_FRAMEBUFFER)
+ bcopy_fromio(sc_vtb_pointer(vtb1, from),
+ sc_vtb_pointer(vtb2, to),
+ count*sizeof(u_int16_t));
+ else
+#endif
+ bcopy((void *)sc_vtb_pointer(vtb1, from),
+ (void *)sc_vtb_pointer(vtb2, to),
+ count*sizeof(u_int16_t));
+}
+
+void
+sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int count)
+{
+ int len;
+
+ if (vtb2->vtb_type != VTB_RINGBUFFER)
+ return;
+
+ while (count > 0) {
+ len = imin(count, vtb2->vtb_size - vtb2->vtb_tail);
+#ifndef __sparc64__
+ if (vtb1->vtb_type == VTB_FRAMEBUFFER)
+ bcopy_fromio(sc_vtb_pointer(vtb1, from),
+ sc_vtb_pointer(vtb2, vtb2->vtb_tail),
+ len*sizeof(u_int16_t));
+ else
+#endif
+ bcopy((void *)sc_vtb_pointer(vtb1, from),
+ (void *)sc_vtb_pointer(vtb2, vtb2->vtb_tail),
+ len*sizeof(u_int16_t));
+ from += len;
+ count -= len;
+ vtb2->vtb_tail = vtb_wrap(vtb2, vtb2->vtb_tail, len);
+ }
+}
+
+void
+sc_vtb_seek(sc_vtb_t *vtb, int pos)
+{
+ vtb->vtb_tail = pos%vtb->vtb_size;
+}
+
+void
+sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr)
+{
+ if (at + count > vtb->vtb_size)
+ count = vtb->vtb_size - at;
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, at), count);
+ else
+#endif
+ fillw(attr | c, (void *)sc_vtb_pointer(vtb, at), count);
+}
+
+void
+sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count)
+{
+ if (from + count > vtb->vtb_size)
+ count = vtb->vtb_size - from;
+ if (to + count > vtb->vtb_size)
+ count = vtb->vtb_size - to;
+ if (count <= 0)
+ return;
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ bcopy_io(sc_vtb_pointer(vtb, from),
+ sc_vtb_pointer(vtb, to), count*sizeof(u_int16_t));
+ else
+#endif
+ bcopy((void *)sc_vtb_pointer(vtb, from),
+ (void *)sc_vtb_pointer(vtb, to), count*sizeof(u_int16_t));
+}
+
+void
+sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr)
+{
+ int len;
+
+ if (at + count > vtb->vtb_size)
+ count = vtb->vtb_size - at;
+ len = vtb->vtb_size - at - count;
+ if (len > 0) {
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ bcopy_io(sc_vtb_pointer(vtb, at + count),
+ sc_vtb_pointer(vtb, at),
+ len*sizeof(u_int16_t));
+ else
+#endif
+ bcopy((void *)sc_vtb_pointer(vtb, at + count),
+ (void *)sc_vtb_pointer(vtb, at),
+ len*sizeof(u_int16_t));
+ }
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, at + len),
+ vtb->vtb_size - at - len);
+ else
+#endif
+ fillw(attr | c, (void *)sc_vtb_pointer(vtb, at + len),
+ vtb->vtb_size - at - len);
+}
+
+void
+sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr)
+{
+ if (at + count > vtb->vtb_size)
+ count = vtb->vtb_size - at;
+ else {
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ bcopy_io(sc_vtb_pointer(vtb, at),
+ sc_vtb_pointer(vtb, at + count),
+ (vtb->vtb_size - at - count)*sizeof(u_int16_t));
+ else
+#endif
+ bcopy((void *)sc_vtb_pointer(vtb, at),
+ (void *)sc_vtb_pointer(vtb, at + count),
+ (vtb->vtb_size - at - count)*sizeof(u_int16_t));
+ }
+#ifndef __sparc64__
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, at), count);
+ else
+#endif
+ fillw(attr | c, (void *)sc_vtb_pointer(vtb, at), count);
+}
diff --git a/sys/dev/syscons/snake/snake_saver.c b/sys/dev/syscons/snake/snake_saver.c
new file mode 100644
index 000000000000..bbdcda31b5e4
--- /dev/null
+++ b/sys/dev/syscons/snake/snake_saver.c
@@ -0,0 +1,133 @@
+/*-
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <machine/pc/display.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+static u_char *message;
+static int *messagep;
+static int messagelen;
+static int blanked;
+
+static int
+snake_saver(video_adapter_t *adp, int blank)
+{
+ static int dirx, diry;
+ int f;
+ sc_softc_t *sc;
+ scr_stat *scp;
+
+/* XXX hack for minimal changes. */
+#define save message
+#define savs messagep
+
+ sc = sc_find_softc(adp, NULL);
+ if (sc == NULL)
+ return EAGAIN;
+ scp = sc->cur_scp;
+
+ if (blank) {
+ if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
+ return EAGAIN;
+ if (blanked <= 0) {
+ sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ vidd_set_hw_cursor(adp, -1, -1);
+ sc_set_border(scp, 0);
+ dirx = (scp->xpos ? 1 : -1);
+ diry = (scp->ypos ?
+ scp->xsize : -scp->xsize);
+ for (f=0; f< messagelen; f++)
+ savs[f] = scp->xpos + scp->ypos*scp->xsize;
+ sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ blanked = 1;
+ }
+ if (blanked++ < 4)
+ return 0;
+ blanked = 1;
+ sc_vtb_putc(&scp->scr, savs[messagelen - 1], sc->scr_map[0x20],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ for (f=messagelen-1; f > 0; f--)
+ savs[f] = savs[f-1];
+ f = savs[0];
+ if ((f % scp->xsize) == 0 ||
+ (f % scp->xsize) == scp->xsize - 1 ||
+ (random() % 50) == 0)
+ dirx = -dirx;
+ if ((f / scp->xsize) == 0 ||
+ (f / scp->xsize) == scp->ysize - 1 ||
+ (random() % 20) == 0)
+ diry = -diry;
+ savs[0] += dirx + diry;
+ for (f=messagelen-1; f>=0; f--)
+ sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ } else
+ blanked = 0;
+
+ return 0;
+}
+
+static int
+snake_init(video_adapter_t *adp)
+{
+ messagelen = strlen(ostype) + 1 + strlen(osrelease);
+ message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
+ sprintf(message, "%s %s", ostype, osrelease);
+ messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK);
+ return 0;
+}
+
+static int
+snake_term(video_adapter_t *adp)
+{
+ free(message, M_DEVBUF);
+ free(messagep, M_DEVBUF);
+ return 0;
+}
+
+static scrn_saver_t snake_module = {
+ "snake_saver", snake_init, snake_term, snake_saver, NULL,
+};
+
+SAVER_MODULE(snake_saver, snake_module);
diff --git a/sys/dev/syscons/star/star_saver.c b/sys/dev/syscons/star/star_saver.c
new file mode 100644
index 000000000000..d4b58cdf68ae
--- /dev/null
+++ b/sys/dev/syscons/star/star_saver.c
@@ -0,0 +1,128 @@
+/*-
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <machine/pc/display.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define NUM_STARS 50
+
+static int blanked;
+
+/*
+ * Alternate saver that got its inspiration from a well known utility
+ * package for an inferior^H^H^H^H^H^Hfamous OS.
+ */
+static int
+star_saver(video_adapter_t *adp, int blank)
+{
+ sc_softc_t *sc;
+ scr_stat *scp;
+ int cell, i;
+ static u_char pattern[] = {"...........++++*** "};
+ static char color16[] = {FG_DARKGREY, FG_LIGHTGREY,
+ FG_WHITE, FG_LIGHTCYAN};
+ static char color8[] = {FG_BLUE, FG_BROWN,
+ FG_LIGHTGREY, FG_CYAN};
+ static char *colors;
+ static u_short stars[NUM_STARS][2];
+
+ sc = sc_find_softc(adp, NULL);
+ if (sc == NULL)
+ return EAGAIN;
+ scp = sc->cur_scp;
+
+ if (blank) {
+ if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
+ return EAGAIN;
+ if (!blanked) {
+ switch (adp->va_mode) {
+ case M_PC98_80x25:
+ case M_PC98_80x30:
+ colors = color8;
+ break;
+ default:
+ colors = color16;
+ break;
+ }
+
+ /* clear the screen and set the border color */
+ sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ vidd_set_hw_cursor(adp, -1, -1);
+ sc_set_border(scp, 0);
+ blanked = TRUE;
+ for(i=0; i<NUM_STARS; i++) {
+ stars[i][0] =
+ random() % (scp->xsize*scp->ysize);
+ stars[i][1] = 0;
+ }
+ }
+ cell = random() % NUM_STARS;
+ sc_vtb_putc(&scp->scr, stars[cell][0],
+ sc->scr_map[pattern[stars[cell][1]]],
+ colors[random()%sizeof(color16)] << 8);
+ if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
+ stars[cell][0] = random() % (scp->xsize*scp->ysize);
+ stars[cell][1] = 0;
+ }
+ } else
+ blanked = FALSE;
+
+ return 0;
+}
+
+static int
+star_init(video_adapter_t *adp)
+{
+ blanked = FALSE;
+ return 0;
+}
+
+static int
+star_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t star_module = {
+ "star_saver", star_init, star_term, star_saver, NULL,
+};
+
+SAVER_MODULE(star_saver, star_module);
diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c
new file mode 100644
index 000000000000..653ff08274a9
--- /dev/null
+++ b/sys/dev/syscons/syscons.c
@@ -0,0 +1,3675 @@
+/*-
+ * Copyright (c) 1992-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sascha Wildner <saw@online.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_compat.h"
+#include "opt_syscons.h"
+#include "opt_splash.h"
+#include "opt_ddb.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/cons.h>
+#include <sys/consio.h>
+#include <sys/kdb.h>
+#include <sys/eventhandler.h>
+#include <sys/fbio.h>
+#include <sys/kbio.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mutex.h>
+#include <sys/priv.h>
+#include <sys/proc.h>
+#include <sys/random.h>
+#include <sys/reboot.h>
+#include <sys/serial.h>
+#include <sys/signalvar.h>
+#include <sys/sysctl.h>
+#include <sys/tty.h>
+#include <sys/power.h>
+
+#include <machine/clock.h>
+#if defined(__sparc64__) || defined(__powerpc__)
+#include <machine/sc_machdep.h>
+#else
+#include <machine/pc/display.h>
+#endif
+#if defined( __i386__) || defined(__amd64__)
+#include <machine/psl.h>
+#include <machine/frame.h>
+#endif
+#include <machine/stdarg.h>
+
+#include <dev/kbd/kbdreg.h>
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define COLD 0
+#define WARM 1
+
+#define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
+#define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
+
+#define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
+
+typedef struct default_attr {
+ int std_color; /* normal hardware color */
+ int rev_color; /* reverse hardware color */
+} default_attr;
+
+static default_attr user_default = {
+ SC_NORM_ATTR,
+ SC_NORM_REV_ATTR,
+};
+
+static int sc_console_unit = -1;
+static int sc_saver_keyb_only = 1;
+static scr_stat *sc_console;
+static struct consdev *sc_consptr;
+static scr_stat main_console;
+static struct tty *main_devs[MAXCONS];
+
+static char init_done = COLD;
+static char shutdown_in_progress = FALSE;
+static char sc_malloc = FALSE;
+
+static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
+static int run_scrn_saver = FALSE; /* should run the saver? */
+static int enable_bell = TRUE; /* enable beeper */
+
+#ifndef SC_DISABLE_REBOOT
+static int enable_reboot = TRUE; /* enable keyboard reboot */
+#endif
+
+#ifndef SC_DISABLE_KDBKEY
+static int enable_kdbkey = TRUE; /* enable keyboard debug */
+#endif
+
+static long scrn_blank_time = 0; /* screen saver timeout value */
+#ifdef DEV_SPLASH
+static int scrn_blanked; /* # of blanked screen */
+static int sticky_splash = FALSE;
+
+static void none_saver(sc_softc_t *sc, int blank) { }
+static void (*current_saver)(sc_softc_t *, int) = none_saver;
+#endif
+
+SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
+SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
+SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
+ &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
+SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell,
+ 0, "enable bell");
+#ifndef SC_DISABLE_REBOOT
+SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW|CTLFLAG_SECURE, &enable_reboot,
+ 0, "enable keyboard reboot");
+#endif
+#ifndef SC_DISABLE_KDBKEY
+SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW|CTLFLAG_SECURE, &enable_kdbkey,
+ 0, "enable keyboard debug");
+#endif
+#if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
+#include "font.h"
+#endif
+
+ tsw_ioctl_t *sc_user_ioctl;
+
+static bios_values_t bios_value;
+
+static int enable_panic_key;
+SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
+ 0, "Enable panic via keypress specified in kbdmap(5)");
+
+#define SC_CONSOLECTL 255
+
+#define VTY_WCHAN(sc, vty) (&SC_DEV(sc, vty))
+
+static int debugger;
+
+/* prototypes */
+static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
+static int scvidprobe(int unit, int flags, int cons);
+static int sckbdprobe(int unit, int flags, int cons);
+static void scmeminit(void *arg);
+static int scdevtounit(struct tty *tp);
+static kbd_callback_func_t sckbdevent;
+static void scinit(int unit, int flags);
+static scr_stat *sc_get_stat(struct tty *tp);
+static void scterm(int unit, int flags);
+static void scshutdown(void *arg, int howto);
+static u_int scgetc(sc_softc_t *sc, u_int flags);
+#define SCGETC_CN 1
+#define SCGETC_NONBLOCK 2
+static void sccnupdate(scr_stat *scp);
+static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
+static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
+static timeout_t scrn_timer;
+static int and_region(int *s1, int *e1, int s2, int e2);
+static void scrn_update(scr_stat *scp, int show_cursor);
+
+#ifdef DEV_SPLASH
+static int scsplash_callback(int event, void *arg);
+static void scsplash_saver(sc_softc_t *sc, int show);
+static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
+static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
+static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
+static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
+static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
+static int wait_scrn_saver_stop(sc_softc_t *sc);
+#define scsplash_stick(stick) (sticky_splash = (stick))
+#else /* !DEV_SPLASH */
+#define scsplash_stick(stick)
+#endif /* DEV_SPLASH */
+
+static int do_switch_scr(sc_softc_t *sc, int s);
+static int vt_proc_alive(scr_stat *scp);
+static int signal_vt_rel(scr_stat *scp);
+static int signal_vt_acq(scr_stat *scp);
+static int finish_vt_rel(scr_stat *scp, int release, int *s);
+static int finish_vt_acq(scr_stat *scp);
+static void exchange_scr(sc_softc_t *sc);
+static void update_cursor_image(scr_stat *scp);
+static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
+static int save_kbd_state(scr_stat *scp);
+static int update_kbd_state(scr_stat *scp, int state, int mask);
+static int update_kbd_leds(scr_stat *scp, int which);
+static timeout_t blink_screen;
+static struct tty *sc_alloc_tty(int, int);
+
+static cn_probe_t sc_cnprobe;
+static cn_init_t sc_cninit;
+static cn_term_t sc_cnterm;
+static cn_getc_t sc_cngetc;
+static cn_putc_t sc_cnputc;
+
+CONSOLE_DRIVER(sc);
+
+static tsw_open_t sctty_open;
+static tsw_close_t sctty_close;
+static tsw_outwakeup_t sctty_outwakeup;
+static tsw_ioctl_t sctty_ioctl;
+static tsw_mmap_t sctty_mmap;
+
+static struct ttydevsw sc_ttydevsw = {
+ .tsw_open = sctty_open,
+ .tsw_close = sctty_close,
+ .tsw_outwakeup = sctty_outwakeup,
+ .tsw_ioctl = sctty_ioctl,
+ .tsw_mmap = sctty_mmap,
+};
+
+static d_ioctl_t consolectl_ioctl;
+
+static struct cdevsw consolectl_devsw = {
+ .d_version = D_VERSION,
+ .d_flags = D_NEEDGIANT,
+ .d_ioctl = consolectl_ioctl,
+ .d_name = "consolectl",
+};
+
+int
+sc_probe_unit(int unit, int flags)
+{
+ if (!scvidprobe(unit, flags, FALSE)) {
+ if (bootverbose)
+ printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit);
+ return ENXIO;
+ }
+
+ /* syscons will be attached even when there is no keyboard */
+ sckbdprobe(unit, flags, FALSE);
+
+ return 0;
+}
+
+/* probe video adapters, return TRUE if found */
+static int
+scvidprobe(int unit, int flags, int cons)
+{
+ /*
+ * Access the video adapter driver through the back door!
+ * Video adapter drivers need to be configured before syscons.
+ * However, when syscons is being probed as the low-level console,
+ * they have not been initialized yet. We force them to initialize
+ * themselves here. XXX
+ */
+ vid_configure(cons ? VIO_PROBE_ONLY : 0);
+
+ return (vid_find_adapter("*", unit) >= 0);
+}
+
+/* probe the keyboard, return TRUE if found */
+static int
+sckbdprobe(int unit, int flags, int cons)
+{
+ /* access the keyboard driver through the backdoor! */
+ kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
+
+ return (kbd_find_keyboard("*", unit) >= 0);
+}
+
+static char
+*adapter_name(video_adapter_t *adp)
+{
+ static struct {
+ int type;
+ char *name[2];
+ } names[] = {
+ { KD_MONO, { "MDA", "MDA" } },
+ { KD_HERCULES, { "Hercules", "Hercules" } },
+ { KD_CGA, { "CGA", "CGA" } },
+ { KD_EGA, { "EGA", "EGA (mono)" } },
+ { KD_VGA, { "VGA", "VGA (mono)" } },
+ { KD_PC98, { "PC-98x1", "PC-98x1" } },
+ { KD_TGA, { "TGA", "TGA" } },
+ { -1, { "Unknown", "Unknown" } },
+ };
+ int i;
+
+ for (i = 0; names[i].type != -1; ++i)
+ if (names[i].type == adp->va_type)
+ break;
+ return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
+}
+
+static void
+sctty_outwakeup(struct tty *tp)
+{
+ size_t len;
+ u_char buf[PCBURST];
+ scr_stat *scp = sc_get_stat(tp);
+
+ if (scp->status & SLKED ||
+ (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
+ return;
+
+ for (;;) {
+ len = ttydisc_getc(tp, buf, sizeof buf);
+ if (len == 0)
+ break;
+ sc_puts(scp, buf, len, 0);
+ }
+}
+
+static struct tty *
+sc_alloc_tty(int index, int devnum)
+{
+ struct sc_ttysoftc *stc;
+ struct tty *tp;
+
+ /* Allocate TTY object and softc to store unit number. */
+ stc = malloc(sizeof(struct sc_ttysoftc), M_DEVBUF, M_WAITOK);
+ stc->st_index = index;
+ stc->st_stat = NULL;
+ tp = tty_alloc_mutex(&sc_ttydevsw, stc, &Giant);
+
+ /* Create device node. */
+ tty_makedev(tp, NULL, "v%r", devnum);
+
+ return (tp);
+}
+
+int
+sc_attach_unit(int unit, int flags)
+{
+ sc_softc_t *sc;
+ scr_stat *scp;
+#ifdef SC_PIXEL_MODE
+ video_info_t info;
+#endif
+ int vc;
+ struct cdev *dev;
+
+ flags &= ~SC_KERNEL_CONSOLE;
+
+ if (sc_console_unit == unit) {
+ /*
+ * If this unit is being used as the system console, we need to
+ * adjust some variables and buffers before and after scinit().
+ */
+ /* assert(sc_console != NULL) */
+ flags |= SC_KERNEL_CONSOLE;
+ scmeminit(NULL);
+ }
+ scinit(unit, flags);
+
+ sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
+ sc->config = flags;
+ scp = sc_get_stat(sc->dev[0]);
+ if (sc_console == NULL) /* sc_console_unit < 0 */
+ sc_console = scp;
+
+#ifdef SC_PIXEL_MODE
+ if ((sc->config & SC_VESA800X600)
+ && (vidd_get_info(sc->adp, M_VESA_800x600, &info) == 0)) {
+#ifdef DEV_SPLASH
+ if (sc->flags & SC_SPLASH_SCRN)
+ splash_term(sc->adp);
+#endif
+ sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
+ sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
+ sc->initial_mode = M_VESA_800x600;
+#ifdef DEV_SPLASH
+ /* put up the splash again! */
+ if (sc->flags & SC_SPLASH_SCRN)
+ splash_init(sc->adp, scsplash_callback, sc);
+#endif
+ }
+#endif /* SC_PIXEL_MODE */
+
+ /* initialize cursor */
+ if (!ISGRAPHSC(scp))
+ update_cursor_image(scp);
+
+ /* get screen update going */
+ scrn_timer(sc);
+
+ /* set up the keyboard */
+ kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ update_kbd_state(scp, scp->status, LOCK_MASK);
+
+ printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n",
+ SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config);
+ if (bootverbose) {
+ printf("%s%d:", SC_DRIVER_NAME, unit);
+ if (sc->adapter >= 0)
+ printf(" fb%d", sc->adapter);
+ if (sc->keyboard >= 0)
+ printf(", kbd%d", sc->keyboard);
+ if (scp->tsw)
+ printf(", terminal emulator: %s (%s)",
+ scp->tsw->te_name, scp->tsw->te_desc);
+ printf("\n");
+ }
+
+ /* register a shutdown callback for the kernel console */
+ if (sc_console_unit == unit)
+ EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
+ (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
+
+ for (vc = 0; vc < sc->vtys; vc++) {
+ if (sc->dev[vc] == NULL) {
+ sc->dev[vc] = sc_alloc_tty(vc, vc + unit * MAXCONS);
+ if (vc == 0 && sc->dev == main_devs)
+ SC_STAT(sc->dev[0]) = &main_console;
+ }
+ /*
+ * The first vty already has struct tty and scr_stat initialized
+ * in scinit(). The other vtys will have these structs when
+ * first opened.
+ */
+ }
+
+ dev = make_dev(&consolectl_devsw, 0, UID_ROOT, GID_WHEEL, 0600,
+ "consolectl");
+ dev->si_drv1 = sc->dev[0];
+
+ return 0;
+}
+
+static void
+scmeminit(void *arg)
+{
+ if (sc_malloc)
+ return;
+ sc_malloc = TRUE;
+
+ /*
+ * As soon as malloc() becomes functional, we had better allocate
+ * various buffers for the kernel console.
+ */
+
+ if (sc_console_unit < 0) /* sc_console == NULL */
+ return;
+
+ /* copy the temporary buffer to the final buffer */
+ sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
+
+#ifndef SC_NO_CUTPASTE
+ sc_alloc_cut_buffer(sc_console, FALSE);
+#endif
+
+#ifndef SC_NO_HISTORY
+ /* initialize history buffer & pointers */
+ sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
+#endif
+}
+
+/* XXX */
+SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
+
+static int
+scdevtounit(struct tty *tp)
+{
+ int vty = SC_VTY(tp);
+
+ if (vty == SC_CONSOLECTL)
+ return ((sc_console != NULL) ? sc_console->sc->unit : -1);
+ else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
+ return -1;
+ else
+ return vty/MAXCONS;
+}
+
+static int
+sctty_open(struct tty *tp)
+{
+ int unit = scdevtounit(tp);
+ sc_softc_t *sc;
+ scr_stat *scp;
+#ifndef __sparc64__
+ keyarg_t key;
+#endif
+
+ DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n",
+ devtoname(tp->t_dev), unit, SC_VTY(tp)));
+
+ sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
+ if (sc == NULL)
+ return ENXIO;
+
+ if (!tty_opened(tp)) {
+ /* Use the current setting of the <-- key as default VERASE. */
+ /* If the Delete key is preferable, an stty is necessary */
+#ifndef __sparc64__
+ if (sc->kbd != NULL) {
+ key.keynum = KEYCODE_BS;
+ kbdd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
+ tp->t_termios.c_cc[VERASE] = key.key.map[0];
+ }
+#endif
+ }
+
+ scp = sc_get_stat(tp);
+ if (scp == NULL) {
+ scp = SC_STAT(tp) = alloc_scp(sc, SC_VTY(tp));
+ if (ISGRAPHSC(scp))
+ sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
+ }
+ if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
+ tp->t_winsize.ws_col = scp->xsize;
+ tp->t_winsize.ws_row = scp->ysize;
+ }
+
+ return (0);
+}
+
+static void
+sctty_close(struct tty *tp)
+{
+ scr_stat *scp;
+ int s;
+
+ if (SC_VTY(tp) != SC_CONSOLECTL) {
+ scp = sc_get_stat(tp);
+ /* were we in the middle of the VT switching process? */
+ DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
+ s = spltty();
+ if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
+ cnavailable(sc_consptr, TRUE);
+ if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
+ DPRINTF(5, ("reset WAIT_REL, "));
+ if (finish_vt_acq(scp) == 0) /* force acknowledge */
+ DPRINTF(5, ("reset WAIT_ACQ, "));
+#ifdef not_yet_done
+ if (scp == &main_console) {
+ scp->pid = 0;
+ scp->proc = NULL;
+ scp->smode.mode = VT_AUTO;
+ }
+ else {
+ sc_vtb_destroy(&scp->vtb);
+#ifndef __sparc64__
+ sc_vtb_destroy(&scp->scr);
+#endif
+ sc_free_history_buffer(scp, scp->ysize);
+ SC_STAT(tp) = NULL;
+ free(scp, M_DEVBUF);
+ }
+#else
+ scp->pid = 0;
+ scp->proc = NULL;
+ scp->smode.mode = VT_AUTO;
+#endif
+ scp->kbd_mode = K_XLATE;
+ if (scp == scp->sc->cur_scp)
+ kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ DPRINTF(5, ("done.\n"));
+ }
+}
+
+#if 0 /* XXX mpsafetty: fix screensaver. What about outwakeup? */
+static int
+scread(struct cdev *dev, struct uio *uio, int flag)
+{
+ if (!sc_saver_keyb_only)
+ sc_touch_scrn_saver();
+ return ttyread(dev, uio, flag);
+}
+#endif
+
+static int
+sckbdevent(keyboard_t *thiskbd, int event, void *arg)
+{
+ sc_softc_t *sc;
+ struct tty *cur_tty;
+ int c, error = 0;
+ size_t len;
+ u_char *cp;
+
+ sc = (sc_softc_t *)arg;
+ /* assert(thiskbd == sc->kbd) */
+
+ mtx_lock(&Giant);
+
+ switch (event) {
+ case KBDIO_KEYINPUT:
+ break;
+ case KBDIO_UNLOADING:
+ sc->kbd = NULL;
+ sc->keyboard = -1;
+ kbd_release(thiskbd, (void *)&sc->keyboard);
+ goto done;
+ default:
+ error = EINVAL;
+ goto done;
+ }
+
+ /*
+ * Loop while there is still input to get from the keyboard.
+ * I don't think this is nessesary, and it doesn't fix
+ * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
+ */
+ while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
+
+ cur_tty = SC_DEV(sc, sc->cur_scp->index);
+ if (!tty_opened(cur_tty))
+ continue;
+
+ if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
+ continue;
+
+ switch (KEYFLAGS(c)) {
+ case 0x0000: /* normal key */
+ ttydisc_rint(cur_tty, KEYCHAR(c), 0);
+ break;
+ case FKEY: /* function key, return string */
+ cp = kbdd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
+ if (cp != NULL) {
+ if (ttydisc_can_bypass(cur_tty)) {
+ ttydisc_rint_bypass(cur_tty, cp, len);
+ } else {
+ while (len-- > 0)
+ ttydisc_rint(cur_tty, *cp++, 0);
+ }
+ }
+ break;
+ case MKEY: /* meta is active, prepend ESC */
+ ttydisc_rint(cur_tty, 0x1b, 0);
+ ttydisc_rint(cur_tty, KEYCHAR(c), 0);
+ break;
+ case BKEY: /* backtab fixed sequence (esc [ Z) */
+ ttydisc_rint(cur_tty, 0x1b, 0);
+ ttydisc_rint(cur_tty, '[', 0);
+ ttydisc_rint(cur_tty, 'Z', 0);
+ break;
+ }
+
+ ttydisc_rint_done(cur_tty);
+ }
+
+ sc->cur_scp->status |= MOUSE_HIDDEN;
+
+done:
+ mtx_unlock(&Giant);
+ return (error);
+}
+
+static int
+sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+{
+ int error;
+ int i;
+ sc_softc_t *sc;
+ scr_stat *scp;
+ int s;
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ int ival;
+#endif
+
+ /* If there is a user_ioctl function call that first */
+ if (sc_user_ioctl) {
+ error = (*sc_user_ioctl)(tp, cmd, data, td);
+ if (error != ENOIOCTL)
+ return error;
+ }
+
+ error = sc_vid_ioctl(tp, cmd, data, td);
+ if (error != ENOIOCTL)
+ return error;
+
+#ifndef SC_NO_HISTORY
+ error = sc_hist_ioctl(tp, cmd, data, td);
+ if (error != ENOIOCTL)
+ return error;
+#endif
+
+#ifndef SC_NO_SYSMOUSE
+ error = sc_mouse_ioctl(tp, cmd, data, td);
+ if (error != ENOIOCTL)
+ return error;
+#endif
+
+ scp = sc_get_stat(tp);
+ /* assert(scp != NULL) */
+ /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
+ sc = scp->sc;
+
+ if (scp->tsw) {
+ error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, td);
+ if (error != ENOIOCTL)
+ return error;
+ }
+
+ switch (cmd) { /* process console hardware related ioctl's */
+
+ case GIO_ATTR: /* get current attributes */
+ /* this ioctl is not processed here, but in the terminal emulator */
+ return ENOTTY;
+
+ case GIO_COLOR: /* is this a color console ? */
+ *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
+ return 0;
+
+ case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
+ if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
+ return EINVAL;
+ s = spltty();
+ scrn_blank_time = *(int *)data;
+ run_scrn_saver = (scrn_blank_time != 0);
+ splx(s);
+ return 0;
+
+ case CONS_CURSORTYPE: /* set cursor type (obsolete) */
+ s = spltty();
+ *(int *)data &= CONS_CURSOR_ATTRS;
+ sc_change_cursor_shape(scp, *(int *)data, -1, -1);
+ splx(s);
+ return 0;
+
+ case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
+ if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
+ ((int *)data)[0] = scp->curr_curs_attr.flags;
+ ((int *)data)[1] = scp->curr_curs_attr.base;
+ ((int *)data)[2] = scp->curr_curs_attr.height;
+ } else {
+ ((int *)data)[0] = sc->curs_attr.flags;
+ ((int *)data)[1] = sc->curs_attr.base;
+ ((int *)data)[2] = sc->curs_attr.height;
+ }
+ return 0;
+
+ case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
+ s = spltty();
+ sc_change_cursor_shape(scp, ((int *)data)[0],
+ ((int *)data)[1], ((int *)data)[2]);
+ splx(s);
+ return 0;
+
+ case CONS_BELLTYPE: /* set bell type sound/visual */
+ if ((*(int *)data) & CONS_VISUAL_BELL)
+ sc->flags |= SC_VISUAL_BELL;
+ else
+ sc->flags &= ~SC_VISUAL_BELL;
+ if ((*(int *)data) & CONS_QUIET_BELL)
+ sc->flags |= SC_QUIET_BELL;
+ else
+ sc->flags &= ~SC_QUIET_BELL;
+ return 0;
+
+ case CONS_GETINFO: /* get current (virtual) console info */
+ {
+ vid_info_t *ptr = (vid_info_t*)data;
+ if (ptr->size == sizeof(struct vid_info)) {
+ ptr->m_num = sc->cur_scp->index;
+ ptr->font_size = scp->font_size;
+ ptr->mv_col = scp->xpos;
+ ptr->mv_row = scp->ypos;
+ ptr->mv_csz = scp->xsize;
+ ptr->mv_rsz = scp->ysize;
+ ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
+ /*
+ * The following fields are filled by the terminal emulator. XXX
+ *
+ * ptr->mv_norm.fore
+ * ptr->mv_norm.back
+ * ptr->mv_rev.fore
+ * ptr->mv_rev.back
+ */
+ ptr->mv_grfc.fore = 0; /* not supported */
+ ptr->mv_grfc.back = 0; /* not supported */
+ ptr->mv_ovscan = scp->border;
+ if (scp == sc->cur_scp)
+ save_kbd_state(scp);
+ ptr->mk_keylock = scp->status & LOCK_MASK;
+ return 0;
+ }
+ return EINVAL;
+ }
+
+ case CONS_GETVERS: /* get version number */
+ *(int*)data = 0x200; /* version 2.0 */
+ return 0;
+
+ case CONS_IDLE: /* see if the screen has been idle */
+ /*
+ * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
+ * the user process may have been writing something on the
+ * screen and syscons is not aware of it. Declare the screen
+ * is NOT idle if it is in one of these modes. But there is
+ * an exception to it; if a screen saver is running in the
+ * graphics mode in the current screen, we should say that the
+ * screen has been idle.
+ */
+ *(int *)data = (sc->flags & SC_SCRN_IDLE)
+ && (!ISGRAPHSC(sc->cur_scp)
+ || (sc->cur_scp->status & SAVER_RUNNING));
+ return 0;
+
+ case CONS_SAVERMODE: /* set saver mode */
+ switch(*(int *)data) {
+ case CONS_NO_SAVER:
+ case CONS_USR_SAVER:
+ /* if a LKM screen saver is running, stop it first. */
+ scsplash_stick(FALSE);
+ saver_mode = *(int *)data;
+ s = spltty();
+#ifdef DEV_SPLASH
+ if ((error = wait_scrn_saver_stop(NULL))) {
+ splx(s);
+ return error;
+ }
+#endif
+ run_scrn_saver = TRUE;
+ if (saver_mode == CONS_USR_SAVER)
+ scp->status |= SAVER_RUNNING;
+ else
+ scp->status &= ~SAVER_RUNNING;
+ scsplash_stick(TRUE);
+ splx(s);
+ break;
+ case CONS_LKM_SAVER:
+ s = spltty();
+ if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
+ scp->status &= ~SAVER_RUNNING;
+ saver_mode = *(int *)data;
+ splx(s);
+ break;
+ default:
+ return EINVAL;
+ }
+ return 0;
+
+ case CONS_SAVERSTART: /* immediately start/stop the screen saver */
+ /*
+ * Note that this ioctl does not guarantee the screen saver
+ * actually starts or stops. It merely attempts to do so...
+ */
+ s = spltty();
+ run_scrn_saver = (*(int *)data != 0);
+ if (run_scrn_saver)
+ sc->scrn_time_stamp -= scrn_blank_time;
+ splx(s);
+ return 0;
+
+ case CONS_SCRSHOT: /* get a screen shot */
+ {
+ int retval, hist_rsz;
+ size_t lsize, csize;
+ vm_offset_t frbp, hstp;
+ unsigned lnum;
+ scrshot_t *ptr = (scrshot_t *)data;
+ void *outp = ptr->buf;
+
+ if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0)
+ return EINVAL;
+ s = spltty();
+ if (ISGRAPHSC(scp)) {
+ splx(s);
+ return EOPNOTSUPP;
+ }
+ hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
+ if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
+ ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
+ splx(s);
+ return EINVAL;
+ }
+
+ lsize = scp->xsize * sizeof(u_int16_t);
+ csize = ptr->xsize * sizeof(u_int16_t);
+ /* Pointer to the last line of framebuffer */
+ frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x *
+ sizeof(u_int16_t);
+ /* Pointer to the last line of target buffer */
+ outp = (char *)outp + ptr->ysize * csize;
+ /* Pointer to the last line of history buffer */
+ if (scp->history != NULL)
+ hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
+ sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
+ else
+ hstp = 0;
+
+ retval = 0;
+ for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
+ if (lnum < scp->ysize) {
+ frbp -= lsize;
+ } else {
+ hstp -= lsize;
+ if (hstp < scp->history->vtb_buffer)
+ hstp += scp->history->vtb_rows * lsize;
+ frbp = hstp;
+ }
+ if (lnum < ptr->y)
+ continue;
+ outp = (char *)outp - csize;
+ retval = copyout((void *)frbp, outp, csize);
+ if (retval != 0)
+ break;
+ }
+ splx(s);
+ return retval;
+ }
+
+ case VT_SETMODE: /* set screen switcher mode */
+ {
+ struct vt_mode *mode;
+ struct proc *p1;
+
+ mode = (struct vt_mode *)data;
+ DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
+ if (scp->smode.mode == VT_PROCESS) {
+ p1 = pfind(scp->pid);
+ if (scp->proc == p1 && scp->proc != td->td_proc) {
+ if (p1)
+ PROC_UNLOCK(p1);
+ DPRINTF(5, ("error EPERM\n"));
+ return EPERM;
+ }
+ if (p1)
+ PROC_UNLOCK(p1);
+ }
+ s = spltty();
+ if (mode->mode == VT_AUTO) {
+ scp->smode.mode = VT_AUTO;
+ scp->proc = NULL;
+ scp->pid = 0;
+ DPRINTF(5, ("VT_AUTO, "));
+ if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
+ cnavailable(sc_consptr, TRUE);
+ /* were we in the middle of the vty switching process? */
+ if (finish_vt_rel(scp, TRUE, &s) == 0)
+ DPRINTF(5, ("reset WAIT_REL, "));
+ if (finish_vt_acq(scp) == 0)
+ DPRINTF(5, ("reset WAIT_ACQ, "));
+ } else {
+ if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
+ || !ISSIGVALID(mode->frsig)) {
+ splx(s);
+ DPRINTF(5, ("error EINVAL\n"));
+ return EINVAL;
+ }
+ DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
+ bcopy(data, &scp->smode, sizeof(struct vt_mode));
+ scp->proc = td->td_proc;
+ scp->pid = scp->proc->p_pid;
+ if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
+ cnavailable(sc_consptr, FALSE);
+ }
+ splx(s);
+ DPRINTF(5, ("\n"));
+ return 0;
+ }
+
+ case VT_GETMODE: /* get screen switcher mode */
+ bcopy(&scp->smode, data, sizeof(struct vt_mode));
+ return 0;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('v', 4):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case VT_RELDISP: /* screen switcher ioctl */
+ s = spltty();
+ /*
+ * This must be the current vty which is in the VT_PROCESS
+ * switching mode...
+ */
+ if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
+ splx(s);
+ return EINVAL;
+ }
+ /* ...and this process is controlling it. */
+ if (scp->proc != td->td_proc) {
+ splx(s);
+ return EPERM;
+ }
+ error = EINVAL;
+ switch(*(int *)data) {
+ case VT_FALSE: /* user refuses to release screen, abort */
+ if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
+ DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit));
+ break;
+ case VT_TRUE: /* user has released screen, go on */
+ if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
+ DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit));
+ break;
+ case VT_ACKACQ: /* acquire acknowledged, switch completed */
+ if ((error = finish_vt_acq(scp)) == 0)
+ DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit));
+ break;
+ default:
+ break;
+ }
+ splx(s);
+ return error;
+
+ case VT_OPENQRY: /* return free virtual console */
+ for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
+ tp = SC_DEV(sc, i);
+ if (!tty_opened(tp)) {
+ *(int *)data = i + 1;
+ return 0;
+ }
+ }
+ return EINVAL;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('v', 5):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case VT_ACTIVATE: /* switch to screen *data */
+ i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
+ s = spltty();
+ error = sc_clean_up(sc->cur_scp);
+ splx(s);
+ if (error)
+ return error;
+ error = sc_switch_scr(sc, i);
+ return (error);
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('v', 6):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case VT_WAITACTIVE: /* wait for switch to occur */
+ i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
+ if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
+ return EINVAL;
+ if (i == sc->cur_scp->index)
+ return 0;
+ error = tsleep(VTY_WCHAN(sc, i), (PZERO + 1) | PCATCH, "waitvt", 0);
+ return error;
+
+ case VT_GETACTIVE: /* get active vty # */
+ *(int *)data = sc->cur_scp->index + 1;
+ return 0;
+
+ case VT_GETINDEX: /* get this vty # */
+ *(int *)data = scp->index + 1;
+ return 0;
+
+ case VT_LOCKSWITCH: /* prevent vty switching */
+ if ((*(int *)data) & 0x01)
+ sc->flags |= SC_SCRN_VTYLOCK;
+ else
+ sc->flags &= ~SC_SCRN_VTYLOCK;
+ return 0;
+
+ case KDENABIO: /* allow io operations */
+ error = priv_check(td, PRIV_IO);
+ if (error != 0)
+ return error;
+ error = securelevel_gt(td->td_ucred, 0);
+ if (error != 0)
+ return error;
+#ifdef __i386__
+ td->td_frame->tf_eflags |= PSL_IOPL;
+#elif defined(__amd64__)
+ td->td_frame->tf_rflags |= PSL_IOPL;
+#endif
+ return 0;
+
+ case KDDISABIO: /* disallow io operations (default) */
+#ifdef __i386__
+ td->td_frame->tf_eflags &= ~PSL_IOPL;
+#elif defined(__amd64__)
+ td->td_frame->tf_rflags &= ~PSL_IOPL;
+#endif
+ return 0;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 20):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDSKBSTATE: /* set keyboard state (locks) */
+ if (*(int *)data & ~LOCK_MASK)
+ return EINVAL;
+ scp->status &= ~LOCK_MASK;
+ scp->status |= *(int *)data;
+ if (scp == sc->cur_scp)
+ update_kbd_state(scp, scp->status, LOCK_MASK);
+ return 0;
+
+ case KDGKBSTATE: /* get keyboard state (locks) */
+ if (scp == sc->cur_scp)
+ save_kbd_state(scp);
+ *(int *)data = scp->status & LOCK_MASK;
+ return 0;
+
+ case KDGETREPEAT: /* get keyboard repeat & delay rates */
+ case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
+ error = kbdd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 67):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDSETRAD: /* set keyboard repeat & delay rates (old) */
+ if (*(int *)data & ~0x7f)
+ return EINVAL;
+ error = kbdd_ioctl(sc->kbd, KDSETRAD, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 7):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDSKBMODE: /* set keyboard mode */
+ switch (*(int *)data) {
+ case K_XLATE: /* switch to XLT ascii mode */
+ case K_RAW: /* switch to RAW scancode mode */
+ case K_CODE: /* switch to CODE mode */
+ scp->kbd_mode = *(int *)data;
+ if (scp == sc->cur_scp)
+ kbdd_ioctl(sc->kbd, KDSKBMODE, data);
+ return 0;
+ default:
+ return EINVAL;
+ }
+ /* NOT REACHED */
+
+ case KDGKBMODE: /* get keyboard mode */
+ *(int *)data = scp->kbd_mode;
+ return 0;
+
+ case KDGKBINFO:
+ error = kbdd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 8):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDMKTONE: /* sound the bell */
+ if (*(int*)data)
+ sc_bell(scp, (*(int*)data)&0xffff,
+ (((*(int*)data)>>16)&0xffff)*hz/1000);
+ else
+ sc_bell(scp, scp->bell_pitch, scp->bell_duration);
+ return 0;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 63):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KIOCSOUND: /* make tone (*data) hz */
+ if (scp == sc->cur_scp) {
+ if (*(int *)data)
+ return sc_tone(*(int *)data);
+ else
+ return sc_tone(0);
+ }
+ return 0;
+
+ case KDGKBTYPE: /* get keyboard type */
+ error = kbdd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL) {
+ /* always return something? XXX */
+ *(int *)data = 0;
+ }
+ return 0;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('K', 66):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case KDSETLED: /* set keyboard LED status */
+ if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
+ return EINVAL;
+ scp->status &= ~LED_MASK;
+ scp->status |= *(int *)data;
+ if (scp == sc->cur_scp)
+ update_kbd_leds(scp, scp->status);
+ return 0;
+
+ case KDGETLED: /* get keyboard LED status */
+ if (scp == sc->cur_scp)
+ save_kbd_state(scp);
+ *(int *)data = scp->status & LED_MASK;
+ return 0;
+
+ case KBADDKBD: /* add/remove keyboard to/from mux */
+ case KBRELKBD:
+ error = kbdd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
+ defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
+ case _IO('c', 110):
+ ival = IOCPARM_IVAL(data);
+ data = (caddr_t)&ival;
+ /* FALLTHROUGH */
+#endif
+ case CONS_SETKBD: /* set the new keyboard */
+ {
+ keyboard_t *newkbd;
+
+ s = spltty();
+ newkbd = kbd_get_keyboard(*(int *)data);
+ if (newkbd == NULL) {
+ splx(s);
+ return EINVAL;
+ }
+ error = 0;
+ if (sc->kbd != newkbd) {
+ i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
+ (void *)&sc->keyboard, sckbdevent, sc);
+ /* i == newkbd->kb_index */
+ if (i >= 0) {
+ if (sc->kbd != NULL) {
+ save_kbd_state(sc->cur_scp);
+ kbd_release(sc->kbd, (void *)&sc->keyboard);
+ }
+ sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
+ sc->keyboard = i;
+ kbdd_ioctl(sc->kbd, KDSKBMODE,
+ (caddr_t)&sc->cur_scp->kbd_mode);
+ update_kbd_state(sc->cur_scp, sc->cur_scp->status,
+ LOCK_MASK);
+ } else {
+ error = EPERM; /* XXX */
+ }
+ }
+ splx(s);
+ return error;
+ }
+
+ case CONS_RELKBD: /* release the current keyboard */
+ s = spltty();
+ error = 0;
+ if (sc->kbd != NULL) {
+ save_kbd_state(sc->cur_scp);
+ error = kbd_release(sc->kbd, (void *)&sc->keyboard);
+ if (error == 0) {
+ sc->kbd = NULL;
+ sc->keyboard = -1;
+ }
+ }
+ splx(s);
+ return error;
+
+ case CONS_GETTERM: /* get the current terminal emulator info */
+ {
+ sc_term_sw_t *sw;
+
+ if (((term_info_t *)data)->ti_index == 0) {
+ sw = scp->tsw;
+ } else {
+ sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
+ }
+ if (sw != NULL) {
+ strncpy(((term_info_t *)data)->ti_name, sw->te_name,
+ sizeof(((term_info_t *)data)->ti_name));
+ strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
+ sizeof(((term_info_t *)data)->ti_desc));
+ ((term_info_t *)data)->ti_flags = 0;
+ return 0;
+ } else {
+ ((term_info_t *)data)->ti_name[0] = '\0';
+ ((term_info_t *)data)->ti_desc[0] = '\0';
+ ((term_info_t *)data)->ti_flags = 0;
+ return EINVAL;
+ }
+ }
+
+ case CONS_SETTERM: /* set the current terminal emulator */
+ s = spltty();
+ error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
+ /* FIXME: what if scp == sc_console! XXX */
+ splx(s);
+ return error;
+
+ case GIO_SCRNMAP: /* get output translation table */
+ bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
+ return 0;
+
+ case PIO_SCRNMAP: /* set output translation table */
+ bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
+ for (i=0; i<sizeof(sc->scr_map); i++) {
+ sc->scr_rmap[sc->scr_map[i]] = i;
+ }
+ return 0;
+
+ case GIO_KEYMAP: /* get keyboard translation table */
+ case PIO_KEYMAP: /* set keyboard translation table */
+ case GIO_DEADKEYMAP: /* get accent key translation table */
+ case PIO_DEADKEYMAP: /* set accent key translation table */
+ case GETFKEY: /* get function key string */
+ case SETFKEY: /* set function key string */
+ error = kbdd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+#ifndef SC_NO_FONT_LOADING
+
+ case PIO_FONT8x8: /* set 8x8 dot font */
+ if (!ISFONTAVAIL(sc->adp->va_flags))
+ return ENXIO;
+ bcopy(data, sc->font_8, 8*256);
+ sc->fonts_loaded |= FONT_8;
+ /*
+ * FONT KLUDGE
+ * Always use the font page #0. XXX
+ * Don't load if the current font size is not 8x8.
+ */
+ if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
+ sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
+ return 0;
+
+ case GIO_FONT8x8: /* get 8x8 dot font */
+ if (!ISFONTAVAIL(sc->adp->va_flags))
+ return ENXIO;
+ if (sc->fonts_loaded & FONT_8) {
+ bcopy(sc->font_8, data, 8*256);
+ return 0;
+ }
+ else
+ return ENXIO;
+
+ case PIO_FONT8x14: /* set 8x14 dot font */
+ if (!ISFONTAVAIL(sc->adp->va_flags))
+ return ENXIO;
+ bcopy(data, sc->font_14, 14*256);
+ sc->fonts_loaded |= FONT_14;
+ /*
+ * FONT KLUDGE
+ * Always use the font page #0. XXX
+ * Don't load if the current font size is not 8x14.
+ */
+ if (ISTEXTSC(sc->cur_scp)
+ && (sc->cur_scp->font_size >= 14)
+ && (sc->cur_scp->font_size < 16))
+ sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
+ return 0;
+
+ case GIO_FONT8x14: /* get 8x14 dot font */
+ if (!ISFONTAVAIL(sc->adp->va_flags))
+ return ENXIO;
+ if (sc->fonts_loaded & FONT_14) {
+ bcopy(sc->font_14, data, 14*256);
+ return 0;
+ }
+ else
+ return ENXIO;
+
+ case PIO_FONT8x16: /* set 8x16 dot font */
+ if (!ISFONTAVAIL(sc->adp->va_flags))
+ return ENXIO;
+ bcopy(data, sc->font_16, 16*256);
+ sc->fonts_loaded |= FONT_16;
+ /*
+ * FONT KLUDGE
+ * Always use the font page #0. XXX
+ * Don't load if the current font size is not 8x16.
+ */
+ if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
+ sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
+ return 0;
+
+ case GIO_FONT8x16: /* get 8x16 dot font */
+ if (!ISFONTAVAIL(sc->adp->va_flags))
+ return ENXIO;
+ if (sc->fonts_loaded & FONT_16) {
+ bcopy(sc->font_16, data, 16*256);
+ return 0;
+ }
+ else
+ return ENXIO;
+
+#endif /* SC_NO_FONT_LOADING */
+
+ default:
+ break;
+ }
+
+ return (ENOIOCTL);
+}
+
+static int
+consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
+ struct thread *td)
+{
+
+ return sctty_ioctl(dev->si_drv1, cmd, data, td);
+}
+
+static void
+sc_cnprobe(struct consdev *cp)
+{
+ int unit;
+ int flags;
+
+ cp->cn_pri = sc_get_cons_priority(&unit, &flags);
+
+ /* a video card is always required */
+ if (!scvidprobe(unit, flags, TRUE))
+ cp->cn_pri = CN_DEAD;
+
+ /* syscons will become console even when there is no keyboard */
+ sckbdprobe(unit, flags, TRUE);
+
+ if (cp->cn_pri == CN_DEAD)
+ return;
+
+ /* initialize required fields */
+ strcpy(cp->cn_name, "ttyv0");
+}
+
+static void
+sc_cninit(struct consdev *cp)
+{
+ int unit;
+ int flags;
+
+ sc_get_cons_priority(&unit, &flags);
+ scinit(unit, flags | SC_KERNEL_CONSOLE);
+ sc_console_unit = unit;
+ sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
+ sc_consptr = cp;
+}
+
+static void
+sc_cnterm(struct consdev *cp)
+{
+ /* we are not the kernel console any more, release everything */
+
+ if (sc_console_unit < 0)
+ return; /* shouldn't happen */
+
+#if 0 /* XXX */
+ sc_clear_screen(sc_console);
+ sccnupdate(sc_console);
+#endif
+
+ scterm(sc_console_unit, SC_KERNEL_CONSOLE);
+ sc_console_unit = -1;
+ sc_console = NULL;
+}
+
+static void
+sc_cnputc(struct consdev *cd, int c)
+{
+ u_char buf[1];
+ scr_stat *scp = sc_console;
+#ifndef SC_NO_HISTORY
+#if 0
+ struct tty *tp;
+#endif
+#endif /* !SC_NO_HISTORY */
+ int s;
+
+ /* assert(sc_console != NULL) */
+
+#ifndef SC_NO_HISTORY
+ if (scp == scp->sc->cur_scp && scp->status & SLKED) {
+ scp->status &= ~SLKED;
+ update_kbd_state(scp, scp->status, SLKED);
+ if (scp->status & BUFFER_SAVED) {
+ if (!sc_hist_restore(scp))
+ sc_remove_cutmarking(scp);
+ scp->status &= ~BUFFER_SAVED;
+ scp->status |= CURSOR_ENABLED;
+ sc_draw_cursor_image(scp);
+ }
+#if 0
+ /*
+ * XXX: Now that TTY's have their own locks, we cannot process
+ * any data after disabling scroll lock. cnputs already holds a
+ * spinlock.
+ */
+ tp = SC_DEV(scp->sc, scp->index);
+ tty_lock(tp);
+ if (tty_opened(tp))
+ sctty_outwakeup(tp);
+ tty_unlock(tp);
+#endif
+ }
+#endif /* !SC_NO_HISTORY */
+
+ buf[0] = c;
+ sc_puts(scp, buf, 1, 1);
+
+ s = spltty(); /* block sckbdevent and scrn_timer */
+ sccnupdate(scp);
+ splx(s);
+}
+
+static int
+sc_cngetc(struct consdev *cd)
+{
+ static struct fkeytab fkey;
+ static int fkeycp;
+ scr_stat *scp;
+ u_char *p;
+ int cur_mode;
+ int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
+ int c;
+
+ /* assert(sc_console != NULL) */
+
+ /*
+ * Stop the screen saver and update the screen if necessary.
+ * What if we have been running in the screen saver code... XXX
+ */
+ sc_touch_scrn_saver();
+ scp = sc_console->sc->cur_scp; /* XXX */
+ sccnupdate(scp);
+
+ if (fkeycp < fkey.len) {
+ splx(s);
+ return fkey.str[fkeycp++];
+ }
+
+ if (scp->sc->kbd == NULL) {
+ splx(s);
+ return -1;
+ }
+
+ /*
+ * Make sure the keyboard is accessible even when the kbd device
+ * driver is disabled.
+ */
+ kbdd_enable(scp->sc->kbd);
+
+ /* we shall always use the keyboard in the XLATE mode here */
+ cur_mode = scp->kbd_mode;
+ scp->kbd_mode = K_XLATE;
+ kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+
+ kbdd_poll(scp->sc->kbd, TRUE);
+ c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK);
+ kbdd_poll(scp->sc->kbd, FALSE);
+
+ scp->kbd_mode = cur_mode;
+ kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ kbdd_disable(scp->sc->kbd);
+ splx(s);
+
+ switch (KEYFLAGS(c)) {
+ case 0: /* normal char */
+ return KEYCHAR(c);
+ case FKEY: /* function key */
+ p = kbdd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
+ fkey.len = fkeycp;
+ if ((p != NULL) && (fkey.len > 0)) {
+ bcopy(p, fkey.str, fkey.len);
+ fkeycp = 1;
+ return fkey.str[0];
+ }
+ return c; /* XXX */
+ case NOKEY:
+ case ERRKEY:
+ default:
+ return -1;
+ }
+ /* NOT REACHED */
+}
+
+static void
+sccnupdate(scr_stat *scp)
+{
+ /* this is a cut-down version of scrn_timer()... */
+
+ if (scp->sc->font_loading_in_progress)
+ return;
+
+ if (debugger > 0 || panicstr || shutdown_in_progress) {
+ sc_touch_scrn_saver();
+ } else if (scp != scp->sc->cur_scp) {
+ return;
+ }
+
+ if (!run_scrn_saver)
+ scp->sc->flags &= ~SC_SCRN_IDLE;
+#ifdef DEV_SPLASH
+ if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
+ if (scp->sc->flags & SC_SCRN_BLANKED)
+ stop_scrn_saver(scp->sc, current_saver);
+#endif
+
+ if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
+ || scp->sc->switch_in_progress)
+ return;
+ /*
+ * FIXME: unlike scrn_timer(), we call scrn_update() from here even
+ * when write_in_progress is non-zero. XXX
+ */
+
+ if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
+ scrn_update(scp, TRUE);
+}
+
+static void
+scrn_timer(void *arg)
+{
+#ifndef PC98
+ static int kbd_interval = 0;
+#endif
+ struct timeval tv;
+ sc_softc_t *sc;
+ scr_stat *scp;
+ int again;
+ int s;
+
+ again = (arg != NULL);
+ if (arg != NULL)
+ sc = (sc_softc_t *)arg;
+ else if (sc_console != NULL)
+ sc = sc_console->sc;
+ else
+ return;
+
+ /* don't do anything when we are performing some I/O operations */
+ if (sc->font_loading_in_progress) {
+ if (again)
+ timeout(scrn_timer, sc, hz / 10);
+ return;
+ }
+ s = spltty();
+
+#ifndef PC98
+ if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
+ /* try to allocate a keyboard automatically */
+ if (++kbd_interval >= 25) {
+ sc->keyboard = sc_allocate_keyboard(sc, -1);
+ if (sc->keyboard >= 0) {
+ sc->kbd = kbd_get_keyboard(sc->keyboard);
+ kbdd_ioctl(sc->kbd, KDSKBMODE,
+ (caddr_t)&sc->cur_scp->kbd_mode);
+ update_kbd_state(sc->cur_scp, sc->cur_scp->status,
+ LOCK_MASK);
+ }
+ kbd_interval = 0;
+ }
+ }
+#endif /* PC98 */
+
+ /* find the vty to update */
+ scp = sc->cur_scp;
+
+ /* should we stop the screen saver? */
+ getmicrouptime(&tv);
+ if (debugger > 0 || panicstr || shutdown_in_progress)
+ sc_touch_scrn_saver();
+ if (run_scrn_saver) {
+ if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
+ sc->flags |= SC_SCRN_IDLE;
+ else
+ sc->flags &= ~SC_SCRN_IDLE;
+ } else {
+ sc->scrn_time_stamp = tv.tv_sec;
+ sc->flags &= ~SC_SCRN_IDLE;
+ if (scrn_blank_time > 0)
+ run_scrn_saver = TRUE;
+ }
+#ifdef DEV_SPLASH
+ if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
+ if (sc->flags & SC_SCRN_BLANKED)
+ stop_scrn_saver(sc, current_saver);
+#endif
+
+ /* should we just return ? */
+ if (sc->blink_in_progress || sc->switch_in_progress
+ || sc->write_in_progress) {
+ if (again)
+ timeout(scrn_timer, sc, hz / 10);
+ splx(s);
+ return;
+ }
+
+ /* Update the screen */
+ scp = sc->cur_scp; /* cur_scp may have changed... */
+ if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
+ scrn_update(scp, TRUE);
+
+#ifdef DEV_SPLASH
+ /* should we activate the screen saver? */
+ if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
+ if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
+ (*current_saver)(sc, TRUE);
+#endif
+
+ if (again)
+ timeout(scrn_timer, sc, hz / 25);
+ splx(s);
+}
+
+static int
+and_region(int *s1, int *e1, int s2, int e2)
+{
+ if (*e1 < s2 || e2 < *s1)
+ return FALSE;
+ *s1 = imax(*s1, s2);
+ *e1 = imin(*e1, e2);
+ return TRUE;
+}
+
+static void
+scrn_update(scr_stat *scp, int show_cursor)
+{
+ int start;
+ int end;
+ int s;
+ int e;
+
+ /* assert(scp == scp->sc->cur_scp) */
+
+ SC_VIDEO_LOCK(scp->sc);
+
+#ifndef SC_NO_CUTPASTE
+ /* remove the previous mouse pointer image if necessary */
+ if (scp->status & MOUSE_VISIBLE) {
+ s = scp->mouse_pos;
+ e = scp->mouse_pos + scp->xsize + 1;
+ if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
+ || and_region(&s, &e, scp->start, scp->end)
+ || ((scp->status & CURSOR_ENABLED) &&
+ (scp->cursor_pos != scp->cursor_oldpos) &&
+ (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
+ || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
+ sc_remove_mouse_image(scp);
+ if (scp->end >= scp->xsize*scp->ysize)
+ scp->end = scp->xsize*scp->ysize - 1;
+ }
+ }
+#endif /* !SC_NO_CUTPASTE */
+
+#if 1
+ /* debug: XXX */
+ if (scp->end >= scp->xsize*scp->ysize) {
+ printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
+ scp->end = scp->xsize*scp->ysize - 1;
+ }
+ if (scp->start < 0) {
+ printf("scrn_update(): scp->start %d < 0\n", scp->start);
+ scp->start = 0;
+ }
+#endif
+
+ /* update screen image */
+ if (scp->start <= scp->end) {
+ if (scp->mouse_cut_end >= 0) {
+ /* there is a marked region for cut & paste */
+ if (scp->mouse_cut_start <= scp->mouse_cut_end) {
+ start = scp->mouse_cut_start;
+ end = scp->mouse_cut_end;
+ } else {
+ start = scp->mouse_cut_end;
+ end = scp->mouse_cut_start - 1;
+ }
+ s = start;
+ e = end;
+ /* does the cut-mark region overlap with the update region? */
+ if (and_region(&s, &e, scp->start, scp->end)) {
+ (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
+ s = 0;
+ e = start - 1;
+ if (and_region(&s, &e, scp->start, scp->end))
+ (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
+ s = end + 1;
+ e = scp->xsize*scp->ysize - 1;
+ if (and_region(&s, &e, scp->start, scp->end))
+ (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
+ } else {
+ (*scp->rndr->draw)(scp, scp->start,
+ scp->end - scp->start + 1, FALSE);
+ }
+ } else {
+ (*scp->rndr->draw)(scp, scp->start,
+ scp->end - scp->start + 1, FALSE);
+ }
+ }
+
+ /* we are not to show the cursor and the mouse pointer... */
+ if (!show_cursor) {
+ scp->end = 0;
+ scp->start = scp->xsize*scp->ysize - 1;
+ SC_VIDEO_UNLOCK(scp->sc);
+ return;
+ }
+
+ /* update cursor image */
+ if (scp->status & CURSOR_ENABLED) {
+ s = scp->start;
+ e = scp->end;
+ /* did cursor move since last time ? */
+ if (scp->cursor_pos != scp->cursor_oldpos) {
+ /* do we need to remove old cursor image ? */
+ if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
+ sc_remove_cursor_image(scp);
+ sc_draw_cursor_image(scp);
+ } else {
+ if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
+ /* cursor didn't move, but has been overwritten */
+ sc_draw_cursor_image(scp);
+ else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
+ /* if it's a blinking cursor, update it */
+ (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
+ sc_inside_cutmark(scp,
+ scp->cursor_pos));
+ }
+ }
+
+#ifndef SC_NO_CUTPASTE
+ /* update "pseudo" mouse pointer image */
+ if (scp->sc->flags & SC_MOUSE_ENABLED) {
+ if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
+ scp->status &= ~MOUSE_MOVED;
+ sc_draw_mouse_image(scp);
+ }
+ }
+#endif /* SC_NO_CUTPASTE */
+
+ scp->end = 0;
+ scp->start = scp->xsize*scp->ysize - 1;
+
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+#ifdef DEV_SPLASH
+static int
+scsplash_callback(int event, void *arg)
+{
+ sc_softc_t *sc;
+ int error;
+
+ sc = (sc_softc_t *)arg;
+
+ switch (event) {
+ case SPLASH_INIT:
+ if (add_scrn_saver(scsplash_saver) == 0) {
+ sc->flags &= ~SC_SAVER_FAILED;
+ run_scrn_saver = TRUE;
+ if (cold && !(boothowto & RB_VERBOSE)) {
+ scsplash_stick(TRUE);
+ (*current_saver)(sc, TRUE);
+ }
+ }
+ return 0;
+
+ case SPLASH_TERM:
+ if (current_saver == scsplash_saver) {
+ scsplash_stick(FALSE);
+ error = remove_scrn_saver(scsplash_saver);
+ if (error)
+ return error;
+ }
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
+
+static void
+scsplash_saver(sc_softc_t *sc, int show)
+{
+ static int busy = FALSE;
+ scr_stat *scp;
+
+ if (busy)
+ return;
+ busy = TRUE;
+
+ scp = sc->cur_scp;
+ if (show) {
+ if (!(sc->flags & SC_SAVER_FAILED)) {
+ if (!(sc->flags & SC_SCRN_BLANKED))
+ set_scrn_saver_mode(scp, -1, NULL, 0);
+ switch (splash(sc->adp, TRUE)) {
+ case 0: /* succeeded */
+ break;
+ case EAGAIN: /* try later */
+ restore_scrn_saver_mode(scp, FALSE);
+ sc_touch_scrn_saver(); /* XXX */
+ break;
+ default:
+ sc->flags |= SC_SAVER_FAILED;
+ scsplash_stick(FALSE);
+ restore_scrn_saver_mode(scp, TRUE);
+ printf("scsplash_saver(): failed to put up the image\n");
+ break;
+ }
+ }
+ } else if (!sticky_splash) {
+ if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
+ restore_scrn_saver_mode(scp, TRUE);
+ }
+ busy = FALSE;
+}
+
+static int
+add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
+{
+#if 0
+ int error;
+
+ if (current_saver != none_saver) {
+ error = remove_scrn_saver(current_saver);
+ if (error)
+ return error;
+ }
+#endif
+ if (current_saver != none_saver)
+ return EBUSY;
+
+ run_scrn_saver = FALSE;
+ saver_mode = CONS_LKM_SAVER;
+ current_saver = this_saver;
+ return 0;
+}
+
+static int
+remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
+{
+ if (current_saver != this_saver)
+ return EINVAL;
+
+#if 0
+ /*
+ * In order to prevent `current_saver' from being called by
+ * the timeout routine `scrn_timer()' while we manipulate
+ * the saver list, we shall set `current_saver' to `none_saver'
+ * before stopping the current saver, rather than blocking by `splXX()'.
+ */
+ current_saver = none_saver;
+ if (scrn_blanked)
+ stop_scrn_saver(this_saver);
+#endif
+
+ /* unblank all blanked screens */
+ wait_scrn_saver_stop(NULL);
+ if (scrn_blanked)
+ return EBUSY;
+
+ current_saver = none_saver;
+ return 0;
+}
+
+static int
+set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
+{
+ int s;
+
+ /* assert(scp == scp->sc->cur_scp) */
+ s = spltty();
+ if (!ISGRAPHSC(scp))
+ sc_remove_cursor_image(scp);
+ scp->splash_save_mode = scp->mode;
+ scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
+ scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
+ scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
+ scp->sc->flags |= SC_SCRN_BLANKED;
+ ++scrn_blanked;
+ splx(s);
+ if (mode < 0)
+ return 0;
+ scp->mode = mode;
+ if (set_mode(scp) == 0) {
+ if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
+ scp->status |= GRAPHICS_MODE;
+#ifndef SC_NO_PALETTE_LOADING
+ if (pal != NULL)
+ vidd_load_palette(scp->sc->adp, pal);
+#endif
+ sc_set_border(scp, border);
+ return 0;
+ } else {
+ s = spltty();
+ scp->mode = scp->splash_save_mode;
+ scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
+ scp->status |= scp->splash_save_status;
+ splx(s);
+ return 1;
+ }
+}
+
+static int
+restore_scrn_saver_mode(scr_stat *scp, int changemode)
+{
+ int mode;
+ int status;
+ int s;
+
+ /* assert(scp == scp->sc->cur_scp) */
+ s = spltty();
+ mode = scp->mode;
+ status = scp->status;
+ scp->mode = scp->splash_save_mode;
+ scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
+ scp->status |= scp->splash_save_status;
+ scp->sc->flags &= ~SC_SCRN_BLANKED;
+ if (!changemode) {
+ if (!ISGRAPHSC(scp))
+ sc_draw_cursor_image(scp);
+ --scrn_blanked;
+ splx(s);
+ return 0;
+ }
+ if (set_mode(scp) == 0) {
+#ifndef SC_NO_PALETTE_LOADING
+ vidd_load_palette(scp->sc->adp, scp->sc->palette);
+#endif
+ --scrn_blanked;
+ splx(s);
+ return 0;
+ } else {
+ scp->mode = mode;
+ scp->status = status;
+ splx(s);
+ return 1;
+ }
+}
+
+static void
+stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
+{
+ (*saver)(sc, FALSE);
+ run_scrn_saver = FALSE;
+ /* the screen saver may have chosen not to stop after all... */
+ if (sc->flags & SC_SCRN_BLANKED)
+ return;
+
+ mark_all(sc->cur_scp);
+ if (sc->delayed_next_scr)
+ sc_switch_scr(sc, sc->delayed_next_scr - 1);
+ if (debugger == 0)
+ wakeup(&scrn_blanked);
+}
+
+static int
+wait_scrn_saver_stop(sc_softc_t *sc)
+{
+ int error = 0;
+
+ while (scrn_blanked > 0) {
+ run_scrn_saver = FALSE;
+ if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
+ error = 0;
+ break;
+ }
+ error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
+ if ((error != 0) && (error != ERESTART))
+ break;
+ }
+ run_scrn_saver = FALSE;
+ return error;
+}
+#endif /* DEV_SPLASH */
+
+void
+sc_touch_scrn_saver(void)
+{
+ scsplash_stick(FALSE);
+ run_scrn_saver = FALSE;
+}
+
+int
+sc_switch_scr(sc_softc_t *sc, u_int next_scr)
+{
+ scr_stat *cur_scp;
+ struct tty *tp;
+ struct proc *p;
+ int s;
+
+ DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
+
+ if (sc->cur_scp == NULL)
+ return (0);
+
+ /* prevent switch if previously requested */
+ if (sc->flags & SC_SCRN_VTYLOCK) {
+ sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
+ sc->cur_scp->bell_duration);
+ return EPERM;
+ }
+
+ /* delay switch if the screen is blanked or being updated */
+ if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
+ || sc->blink_in_progress) {
+ sc->delayed_next_scr = next_scr + 1;
+ sc_touch_scrn_saver();
+ DPRINTF(5, ("switch delayed\n"));
+ return 0;
+ }
+ sc->delayed_next_scr = 0;
+
+ s = spltty();
+ cur_scp = sc->cur_scp;
+
+ /* we are in the middle of the vty switching process... */
+ if (sc->switch_in_progress
+ && (cur_scp->smode.mode == VT_PROCESS)
+ && cur_scp->proc) {
+ p = pfind(cur_scp->pid);
+ if (cur_scp->proc != p) {
+ if (p)
+ PROC_UNLOCK(p);
+ /*
+ * The controlling process has died!!. Do some clean up.
+ * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
+ * are not reset here yet; they will be cleared later.
+ */
+ DPRINTF(5, ("cur_scp controlling process %d died, ",
+ cur_scp->pid));
+ if (cur_scp->status & SWITCH_WAIT_REL) {
+ /*
+ * Force the previous switch to finish, but return now
+ * with error.
+ */
+ DPRINTF(5, ("reset WAIT_REL, "));
+ finish_vt_rel(cur_scp, TRUE, &s);
+ splx(s);
+ DPRINTF(5, ("finishing previous switch\n"));
+ return EINVAL;
+ } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
+ /* let's assume screen switch has been completed. */
+ DPRINTF(5, ("reset WAIT_ACQ, "));
+ finish_vt_acq(cur_scp);
+ } else {
+ /*
+ * We are in between screen release and acquisition, and
+ * reached here via scgetc() or scrn_timer() which has
+ * interrupted exchange_scr(). Don't do anything stupid.
+ */
+ DPRINTF(5, ("waiting nothing, "));
+ }
+ } else {
+ if (p)
+ PROC_UNLOCK(p);
+ /*
+ * The controlling process is alive, but not responding...
+ * It is either buggy or it may be just taking time.
+ * The following code is a gross kludge to cope with this
+ * problem for which there is no clean solution. XXX
+ */
+ if (cur_scp->status & SWITCH_WAIT_REL) {
+ switch (sc->switch_in_progress++) {
+ case 1:
+ break;
+ case 2:
+ DPRINTF(5, ("sending relsig again, "));
+ signal_vt_rel(cur_scp);
+ break;
+ case 3:
+ break;
+ case 4:
+ default:
+ /*
+ * Act as if the controlling program returned
+ * VT_FALSE.
+ */
+ DPRINTF(5, ("force reset WAIT_REL, "));
+ finish_vt_rel(cur_scp, FALSE, &s);
+ splx(s);
+ DPRINTF(5, ("act as if VT_FALSE was seen\n"));
+ return EINVAL;
+ }
+ } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
+ switch (sc->switch_in_progress++) {
+ case 1:
+ break;
+ case 2:
+ DPRINTF(5, ("sending acqsig again, "));
+ signal_vt_acq(cur_scp);
+ break;
+ case 3:
+ break;
+ case 4:
+ default:
+ /* clear the flag and finish the previous switch */
+ DPRINTF(5, ("force reset WAIT_ACQ, "));
+ finish_vt_acq(cur_scp);
+ break;
+ }
+ }
+ }
+ }
+
+ /*
+ * Return error if an invalid argument is given, or vty switch
+ * is still in progress.
+ */
+ if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
+ || sc->switch_in_progress) {
+ splx(s);
+ sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
+ DPRINTF(5, ("error 1\n"));
+ return EINVAL;
+ }
+
+ /*
+ * Don't allow switching away from the graphics mode vty
+ * if the switch mode is VT_AUTO, unless the next vty is the same
+ * as the current or the current vty has been closed (but showing).
+ */
+ tp = SC_DEV(sc, cur_scp->index);
+ if ((cur_scp->index != next_scr)
+ && tty_opened(tp)
+ && (cur_scp->smode.mode == VT_AUTO)
+ && ISGRAPHSC(cur_scp)) {
+ splx(s);
+ sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
+ DPRINTF(5, ("error, graphics mode\n"));
+ return EINVAL;
+ }
+
+ /*
+ * Is the wanted vty open? Don't allow switching to a closed vty.
+ * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
+ * Note that we always allow the user to switch to the kernel
+ * console even if it is closed.
+ */
+ if ((sc_console == NULL) || (next_scr != sc_console->index)) {
+ tp = SC_DEV(sc, next_scr);
+ if (!tty_opened(tp)) {
+ splx(s);
+ sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
+ DPRINTF(5, ("error 2, requested vty isn't open!\n"));
+ return EINVAL;
+ }
+ if ((debugger > 0) && (SC_STAT(tp)->smode.mode == VT_PROCESS)) {
+ splx(s);
+ DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
+ return EINVAL;
+ }
+ }
+
+ /* this is the start of vty switching process... */
+ ++sc->switch_in_progress;
+ sc->old_scp = cur_scp;
+ sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
+ if (sc->new_scp == sc->old_scp) {
+ sc->switch_in_progress = 0;
+ /*
+ * XXX wakeup() locks the scheduler lock which will hang if
+ * the lock is in an in-between state, e.g., when we stop at
+ * a breakpoint at fork_exit. It has always been wrong to call
+ * wakeup() when the debugger is active. In RELENG_4, wakeup()
+ * is supposed to be locked by splhigh(), but the debugger may
+ * be invoked at splhigh().
+ */
+ if (debugger == 0)
+ wakeup(VTY_WCHAN(sc,next_scr));
+ splx(s);
+ DPRINTF(5, ("switch done (new == old)\n"));
+ return 0;
+ }
+
+ /* has controlling process died? */
+ vt_proc_alive(sc->old_scp);
+ vt_proc_alive(sc->new_scp);
+
+ /* wait for the controlling process to release the screen, if necessary */
+ if (signal_vt_rel(sc->old_scp)) {
+ splx(s);
+ return 0;
+ }
+
+ /* go set up the new vty screen */
+ splx(s);
+ exchange_scr(sc);
+ s = spltty();
+
+ /* wake up processes waiting for this vty */
+ if (debugger == 0)
+ wakeup(VTY_WCHAN(sc,next_scr));
+
+ /* wait for the controlling process to acknowledge, if necessary */
+ if (signal_vt_acq(sc->cur_scp)) {
+ splx(s);
+ return 0;
+ }
+
+ sc->switch_in_progress = 0;
+ if (sc->unit == sc_console_unit)
+ cnavailable(sc_consptr, TRUE);
+ splx(s);
+ DPRINTF(5, ("switch done\n"));
+
+ return 0;
+}
+
+static int
+do_switch_scr(sc_softc_t *sc, int s)
+{
+ vt_proc_alive(sc->new_scp);
+
+ splx(s);
+ exchange_scr(sc);
+ s = spltty();
+ /* sc->cur_scp == sc->new_scp */
+ wakeup(VTY_WCHAN(sc,sc->cur_scp->index));
+
+ /* wait for the controlling process to acknowledge, if necessary */
+ if (!signal_vt_acq(sc->cur_scp)) {
+ sc->switch_in_progress = 0;
+ if (sc->unit == sc_console_unit)
+ cnavailable(sc_consptr, TRUE);
+ }
+
+ return s;
+}
+
+static int
+vt_proc_alive(scr_stat *scp)
+{
+ struct proc *p;
+
+ if (scp->proc) {
+ if ((p = pfind(scp->pid)) != NULL)
+ PROC_UNLOCK(p);
+ if (scp->proc == p)
+ return TRUE;
+ scp->proc = NULL;
+ scp->smode.mode = VT_AUTO;
+ DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
+ }
+ return FALSE;
+}
+
+static int
+signal_vt_rel(scr_stat *scp)
+{
+ if (scp->smode.mode != VT_PROCESS)
+ return FALSE;
+ scp->status |= SWITCH_WAIT_REL;
+ PROC_LOCK(scp->proc);
+ psignal(scp->proc, scp->smode.relsig);
+ PROC_UNLOCK(scp->proc);
+ DPRINTF(5, ("sending relsig to %d\n", scp->pid));
+ return TRUE;
+}
+
+static int
+signal_vt_acq(scr_stat *scp)
+{
+ if (scp->smode.mode != VT_PROCESS)
+ return FALSE;
+ if (scp->sc->unit == sc_console_unit)
+ cnavailable(sc_consptr, FALSE);
+ scp->status |= SWITCH_WAIT_ACQ;
+ PROC_LOCK(scp->proc);
+ psignal(scp->proc, scp->smode.acqsig);
+ PROC_UNLOCK(scp->proc);
+ DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
+ return TRUE;
+}
+
+static int
+finish_vt_rel(scr_stat *scp, int release, int *s)
+{
+ if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
+ scp->status &= ~SWITCH_WAIT_REL;
+ if (release)
+ *s = do_switch_scr(scp->sc, *s);
+ else
+ scp->sc->switch_in_progress = 0;
+ return 0;
+ }
+ return EINVAL;
+}
+
+static int
+finish_vt_acq(scr_stat *scp)
+{
+ if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
+ scp->status &= ~SWITCH_WAIT_ACQ;
+ scp->sc->switch_in_progress = 0;
+ return 0;
+ }
+ return EINVAL;
+}
+
+static void
+exchange_scr(sc_softc_t *sc)
+{
+ scr_stat *scp;
+
+ /* save the current state of video and keyboard */
+ sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
+ if (!ISGRAPHSC(sc->old_scp))
+ sc_remove_cursor_image(sc->old_scp);
+ if (sc->old_scp->kbd_mode == K_XLATE)
+ save_kbd_state(sc->old_scp);
+
+ /* set up the video for the new screen */
+ scp = sc->cur_scp = sc->new_scp;
+#ifdef PC98
+ if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp))
+#else
+ if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
+#endif
+ set_mode(scp);
+#ifndef __sparc64__
+ else
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
+ (void *)sc->adp->va_window, FALSE);
+#endif
+ scp->status |= MOUSE_HIDDEN;
+ sc_move_cursor(scp, scp->xpos, scp->ypos);
+ if (!ISGRAPHSC(scp))
+ sc_set_cursor_image(scp);
+#ifndef SC_NO_PALETTE_LOADING
+ if (ISGRAPHSC(sc->old_scp))
+ vidd_load_palette(sc->adp, sc->palette);
+#endif
+ sc_set_border(scp, scp->border);
+
+ /* set up the keyboard for the new screen */
+ if (sc->old_scp->kbd_mode != scp->kbd_mode)
+ kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ update_kbd_state(scp, scp->status, LOCK_MASK);
+
+ mark_all(scp);
+}
+
+void
+sc_puts(scr_stat *scp, u_char *buf, int len, int kernel)
+{
+ int need_unlock = 0;
+
+#ifdef DEV_SPLASH
+ /* make screensaver happy */
+ if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
+ run_scrn_saver = FALSE;
+#endif
+
+ if (scp->tsw) {
+ if (!kdb_active && !mtx_owned(&scp->scr_lock)) {
+ need_unlock = 1;
+ mtx_lock_spin(&scp->scr_lock);
+ }
+ (*scp->tsw->te_puts)(scp, buf, len, kernel);
+ if (need_unlock)
+ mtx_unlock_spin(&scp->scr_lock);
+ }
+
+ if (scp->sc->delayed_next_scr)
+ sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
+}
+
+void
+sc_draw_cursor_image(scr_stat *scp)
+{
+ /* assert(scp == scp->sc->cur_scp); */
+ SC_VIDEO_LOCK(scp->sc);
+ (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
+ scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
+ sc_inside_cutmark(scp, scp->cursor_pos));
+ scp->cursor_oldpos = scp->cursor_pos;
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+void
+sc_remove_cursor_image(scr_stat *scp)
+{
+ /* assert(scp == scp->sc->cur_scp); */
+ SC_VIDEO_LOCK(scp->sc);
+ (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
+ scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
+ sc_inside_cutmark(scp, scp->cursor_oldpos));
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+static void
+update_cursor_image(scr_stat *scp)
+{
+ /* assert(scp == scp->sc->cur_scp); */
+ sc_remove_cursor_image(scp);
+ sc_set_cursor_image(scp);
+ sc_draw_cursor_image(scp);
+}
+
+void
+sc_set_cursor_image(scr_stat *scp)
+{
+ scp->curs_attr.flags = scp->curr_curs_attr.flags;
+ if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
+ /* hidden cursor is internally represented as zero-height underline */
+ scp->curs_attr.flags = CONS_CHAR_CURSOR;
+ scp->curs_attr.base = scp->curs_attr.height = 0;
+ } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
+ scp->curs_attr.base = imin(scp->curr_curs_attr.base,
+ scp->font_size - 1);
+ scp->curs_attr.height = imin(scp->curr_curs_attr.height,
+ scp->font_size - scp->curs_attr.base);
+ } else { /* block cursor */
+ scp->curs_attr.base = 0;
+ scp->curs_attr.height = scp->font_size;
+ }
+
+ /* assert(scp == scp->sc->cur_scp); */
+ SC_VIDEO_LOCK(scp->sc);
+ (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
+ scp->curs_attr.flags & CONS_BLINK_CURSOR);
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+static void
+change_cursor_shape(scr_stat *scp, int flags, int base, int height)
+{
+ if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
+ sc_remove_cursor_image(scp);
+
+ if (base >= 0)
+ scp->curr_curs_attr.base = base;
+ if (height >= 0)
+ scp->curr_curs_attr.height = height;
+ if (flags & CONS_RESET_CURSOR)
+ scp->curr_curs_attr = scp->dflt_curs_attr;
+ else
+ scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
+
+ if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
+ sc_set_cursor_image(scp);
+ sc_draw_cursor_image(scp);
+ }
+}
+
+void
+sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
+{
+ sc_softc_t *sc;
+ struct tty *tp;
+ int s;
+ int i;
+
+ s = spltty();
+ if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
+ /* local (per vty) change */
+ change_cursor_shape(scp, flags, base, height);
+ splx(s);
+ return;
+ }
+
+ /* global change */
+ sc = scp->sc;
+ if (base >= 0)
+ sc->curs_attr.base = base;
+ if (height >= 0)
+ sc->curs_attr.height = height;
+ if (flags != -1) {
+ if (flags & CONS_RESET_CURSOR)
+ sc->curs_attr = sc->dflt_curs_attr;
+ else
+ sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
+ }
+
+ for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
+ if ((tp = SC_DEV(sc, i)) == NULL)
+ continue;
+ if ((scp = sc_get_stat(tp)) == NULL)
+ continue;
+ scp->dflt_curs_attr = sc->curs_attr;
+ change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
+ }
+ splx(s);
+}
+
+static void
+scinit(int unit, int flags)
+{
+
+ /*
+ * When syscons is being initialized as the kernel console, malloc()
+ * is not yet functional, because various kernel structures has not been
+ * fully initialized yet. Therefore, we need to declare the following
+ * static buffers for the console. This is less than ideal,
+ * but is necessry evil for the time being. XXX
+ */
+#ifdef PC98
+ static u_short sc_buffer[ROW*COL*2];/* XXX */
+#else
+ static u_short sc_buffer[ROW*COL]; /* XXX */
+#endif
+#ifndef SC_NO_FONT_LOADING
+ static u_char font_8[256*8];
+ static u_char font_14[256*14];
+ static u_char font_16[256*16];
+#endif
+
+ sc_softc_t *sc;
+ scr_stat *scp;
+ video_adapter_t *adp;
+ int col;
+ int row;
+ int i;
+
+ /* one time initialization */
+ if (init_done == COLD)
+ sc_get_bios_values(&bios_value);
+ init_done = WARM;
+
+ /*
+ * Allocate resources. Even if we are being called for the second
+ * time, we must allocate them again, because they might have
+ * disappeared...
+ */
+ sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
+ if ((sc->flags & SC_INIT_DONE) == 0)
+ SC_VIDEO_LOCKINIT(sc);
+
+ adp = NULL;
+ if (sc->adapter >= 0) {
+ vid_release(sc->adp, (void *)&sc->adapter);
+ adp = sc->adp;
+ sc->adp = NULL;
+ }
+ if (sc->keyboard >= 0) {
+ DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
+ i = kbd_release(sc->kbd, (void *)&sc->keyboard);
+ DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
+ if (sc->kbd != NULL) {
+ DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
+ unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
+ }
+ sc->kbd = NULL;
+ }
+ sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
+ sc->adp = vid_get_adapter(sc->adapter);
+ /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
+
+ sc->keyboard = sc_allocate_keyboard(sc, unit);
+ DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
+
+ sc->kbd = kbd_get_keyboard(sc->keyboard);
+ if (sc->kbd != NULL) {
+ DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
+ unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
+ }
+
+ if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
+
+ sc->initial_mode = sc->adp->va_initial_mode;
+
+#ifndef SC_NO_FONT_LOADING
+ if (flags & SC_KERNEL_CONSOLE) {
+ sc->font_8 = font_8;
+ sc->font_14 = font_14;
+ sc->font_16 = font_16;
+ } else if (sc->font_8 == NULL) {
+ /* assert(sc_malloc) */
+ sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
+ sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
+ sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
+ }
+#endif
+
+ /* extract the hardware cursor location and hide the cursor for now */
+ vidd_read_hw_cursor(sc->adp, &col, &row);
+ vidd_set_hw_cursor(sc->adp, -1, -1);
+
+ /* set up the first console */
+ sc->first_vty = unit*MAXCONS;
+ sc->vtys = MAXCONS; /* XXX: should be configurable */
+ if (flags & SC_KERNEL_CONSOLE) {
+ /*
+ * Set up devs structure but don't use it yet, calling make_dev()
+ * might panic kernel. Wait for sc_attach_unit() to actually
+ * create the devices.
+ */
+ sc->dev = main_devs;
+ scp = &main_console;
+ init_scp(sc, sc->first_vty, scp);
+ sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
+ (void *)sc_buffer, FALSE);
+
+ /* move cursors to the initial positions */
+ if (col >= scp->xsize)
+ col = 0;
+ if (row >= scp->ysize)
+ row = scp->ysize - 1;
+ scp->xpos = col;
+ scp->ypos = row;
+ scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
+
+ if (sc_init_emulator(scp, SC_DFLT_TERM))
+ sc_init_emulator(scp, "*");
+ (*scp->tsw->te_default_attr)(scp,
+ user_default.std_color,
+ user_default.rev_color);
+ } else {
+ /* assert(sc_malloc) */
+ sc->dev = malloc(sizeof(struct tty *)*sc->vtys, M_DEVBUF,
+ M_WAITOK|M_ZERO);
+ sc->dev[0] = sc_alloc_tty(0, unit * MAXCONS);
+ scp = alloc_scp(sc, sc->first_vty);
+ SC_STAT(sc->dev[0]) = scp;
+ }
+ sc->cur_scp = scp;
+
+#ifndef __sparc64__
+ /* copy screen to temporary buffer */
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
+ (void *)scp->sc->adp->va_window, FALSE);
+ if (ISTEXTSC(scp))
+ sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
+#endif
+
+ if (bios_value.cursor_end < scp->font_size)
+ sc->dflt_curs_attr.base = scp->font_size -
+ bios_value.cursor_end - 1;
+ else
+ sc->dflt_curs_attr.base = 0;
+ i = bios_value.cursor_end - bios_value.cursor_start + 1;
+ sc->dflt_curs_attr.height = imin(i, scp->font_size);
+ sc->dflt_curs_attr.flags = 0;
+ sc->curs_attr = sc->dflt_curs_attr;
+ scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
+
+#ifndef SC_NO_SYSMOUSE
+ sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
+#endif
+ if (!ISGRAPHSC(scp)) {
+ sc_set_cursor_image(scp);
+ sc_draw_cursor_image(scp);
+ }
+
+ /* save font and palette */
+#ifndef SC_NO_FONT_LOADING
+ sc->fonts_loaded = 0;
+ if (ISFONTAVAIL(sc->adp->va_flags)) {
+#ifdef SC_DFLT_FONT
+ bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
+ bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
+ bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
+ sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
+ if (scp->font_size < 14) {
+ sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
+ } else if (scp->font_size >= 16) {
+ sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256);
+ } else {
+ sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256);
+ }
+#else /* !SC_DFLT_FONT */
+ if (scp->font_size < 14) {
+ sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
+ sc->fonts_loaded = FONT_8;
+ } else if (scp->font_size >= 16) {
+ sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256);
+ sc->fonts_loaded = FONT_16;
+ } else {
+ sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256);
+ sc->fonts_loaded = FONT_14;
+ }
+#endif /* SC_DFLT_FONT */
+ /* FONT KLUDGE: always use the font page #0. XXX */
+ sc_show_font(scp, 0);
+ }
+#endif /* !SC_NO_FONT_LOADING */
+
+#ifndef SC_NO_PALETTE_LOADING
+ vidd_save_palette(sc->adp, sc->palette);
+#endif
+
+#ifdef DEV_SPLASH
+ if (!(sc->flags & SC_SPLASH_SCRN)) {
+ /* we are ready to put up the splash image! */
+ splash_init(sc->adp, scsplash_callback, sc);
+ sc->flags |= SC_SPLASH_SCRN;
+ }
+#endif
+ }
+
+ /* the rest is not necessary, if we have done it once */
+ if (sc->flags & SC_INIT_DONE)
+ return;
+
+ /* initialize mapscrn arrays to a one to one map */
+ for (i = 0; i < sizeof(sc->scr_map); i++)
+ sc->scr_map[i] = sc->scr_rmap[i] = i;
+#ifdef PC98
+ sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */
+#endif
+
+ sc->flags |= SC_INIT_DONE;
+}
+
+static void
+scterm(int unit, int flags)
+{
+ sc_softc_t *sc;
+ scr_stat *scp;
+
+ sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
+ if (sc == NULL)
+ return; /* shouldn't happen */
+
+#ifdef DEV_SPLASH
+ /* this console is no longer available for the splash screen */
+ if (sc->flags & SC_SPLASH_SCRN) {
+ splash_term(sc->adp);
+ sc->flags &= ~SC_SPLASH_SCRN;
+ }
+#endif
+
+#if 0 /* XXX */
+ /* move the hardware cursor to the upper-left corner */
+ vidd_set_hw_cursor(sc->adp, 0, 0);
+#endif
+
+ /* release the keyboard and the video card */
+ if (sc->keyboard >= 0)
+ kbd_release(sc->kbd, &sc->keyboard);
+ if (sc->adapter >= 0)
+ vid_release(sc->adp, &sc->adapter);
+
+ /* stop the terminal emulator, if any */
+ scp = sc_get_stat(sc->dev[0]);
+ if (scp->tsw)
+ (*scp->tsw->te_term)(scp, &scp->ts);
+ if (scp->ts != NULL)
+ free(scp->ts, M_DEVBUF);
+ mtx_destroy(&scp->scr_lock);
+
+ /* clear the structure */
+ if (!(flags & SC_KERNEL_CONSOLE)) {
+ /* XXX: We need delete_dev() for this */
+ free(sc->dev, M_DEVBUF);
+#if 0
+ /* XXX: We need a ttyunregister for this */
+ free(sc->tty, M_DEVBUF);
+#endif
+#ifndef SC_NO_FONT_LOADING
+ free(sc->font_8, M_DEVBUF);
+ free(sc->font_14, M_DEVBUF);
+ free(sc->font_16, M_DEVBUF);
+#endif
+ /* XXX vtb, history */
+ }
+ bzero(sc, sizeof(*sc));
+ sc->keyboard = -1;
+ sc->adapter = -1;
+}
+
+static void
+scshutdown(void *arg, int howto)
+{
+ /* assert(sc_console != NULL) */
+
+ sc_touch_scrn_saver();
+ if (!cold && sc_console
+ && sc_console->sc->cur_scp->smode.mode == VT_AUTO
+ && sc_console->smode.mode == VT_AUTO)
+ sc_switch_scr(sc_console->sc, sc_console->index);
+ shutdown_in_progress = TRUE;
+}
+
+int
+sc_clean_up(scr_stat *scp)
+{
+#ifdef DEV_SPLASH
+ int error;
+#endif
+
+ if (scp->sc->flags & SC_SCRN_BLANKED) {
+ sc_touch_scrn_saver();
+#ifdef DEV_SPLASH
+ if ((error = wait_scrn_saver_stop(scp->sc)))
+ return error;
+#endif
+ }
+ scp->status |= MOUSE_HIDDEN;
+ sc_remove_mouse_image(scp);
+ sc_remove_cutmarking(scp);
+ return 0;
+}
+
+void
+sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
+{
+ sc_vtb_t new;
+ sc_vtb_t old;
+
+ old = scp->vtb;
+ sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
+ if (!discard && (old.vtb_flags & VTB_VALID)) {
+ /* retain the current cursor position and buffer contants */
+ scp->cursor_oldpos = scp->cursor_pos;
+ /*
+ * This works only if the old buffer has the same size as or larger
+ * than the new one. XXX
+ */
+ sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
+ scp->vtb = new;
+ } else {
+ scp->vtb = new;
+ sc_vtb_destroy(&old);
+ }
+
+#ifndef SC_NO_SYSMOUSE
+ /* move the mouse cursor at the center of the screen */
+ sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
+#endif
+}
+
+static scr_stat
+*alloc_scp(sc_softc_t *sc, int vty)
+{
+ scr_stat *scp;
+
+ /* assert(sc_malloc) */
+
+ scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
+ init_scp(sc, vty, scp);
+
+ sc_alloc_scr_buffer(scp, TRUE, TRUE);
+ if (sc_init_emulator(scp, SC_DFLT_TERM))
+ sc_init_emulator(scp, "*");
+
+#ifndef SC_NO_CUTPASTE
+ sc_alloc_cut_buffer(scp, TRUE);
+#endif
+
+#ifndef SC_NO_HISTORY
+ sc_alloc_history_buffer(scp, 0, 0, TRUE);
+#endif
+
+ return scp;
+}
+
+static void
+init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
+{
+ video_info_t info;
+
+ bzero(scp, sizeof(*scp));
+
+ scp->index = vty;
+ scp->sc = sc;
+ scp->status = 0;
+ scp->mode = sc->initial_mode;
+ vidd_get_info(sc->adp, scp->mode, &info);
+ if (info.vi_flags & V_INFO_GRAPHICS) {
+ scp->status |= GRAPHICS_MODE;
+ scp->xpixel = info.vi_width;
+ scp->ypixel = info.vi_height;
+ scp->xsize = info.vi_width/info.vi_cwidth;
+ scp->ysize = info.vi_height/info.vi_cheight;
+ scp->font_size = 0;
+ scp->font = NULL;
+ } else {
+ scp->xsize = info.vi_width;
+ scp->ysize = info.vi_height;
+ scp->xpixel = scp->xsize*info.vi_cwidth;
+ scp->ypixel = scp->ysize*info.vi_cheight;
+ scp->font_size = info.vi_cheight;
+ scp->font_width = info.vi_cwidth;
+ if (info.vi_cheight < 14) {
+#ifndef SC_NO_FONT_LOADING
+ scp->font = sc->font_8;
+#else
+ scp->font = NULL;
+#endif
+ } else if (info.vi_cheight >= 16) {
+#ifndef SC_NO_FONT_LOADING
+ scp->font = sc->font_16;
+#else
+ scp->font = NULL;
+#endif
+ } else {
+#ifndef SC_NO_FONT_LOADING
+ scp->font = sc->font_14;
+#else
+ scp->font = NULL;
+#endif
+ }
+ }
+ sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
+#ifndef __sparc64__
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
+#endif
+ scp->xoff = scp->yoff = 0;
+ scp->xpos = scp->ypos = 0;
+ scp->start = scp->xsize * scp->ysize - 1;
+ scp->end = 0;
+ scp->tsw = NULL;
+ scp->ts = NULL;
+ scp->rndr = NULL;
+ scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
+ scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
+ scp->mouse_cut_start = scp->xsize*scp->ysize;
+ scp->mouse_cut_end = -1;
+ scp->mouse_signal = 0;
+ scp->mouse_pid = 0;
+ scp->mouse_proc = NULL;
+ scp->kbd_mode = K_XLATE;
+ scp->bell_pitch = bios_value.bell_pitch;
+ scp->bell_duration = BELL_DURATION;
+ scp->status |= (bios_value.shift_state & NLKED);
+ scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
+ scp->pid = 0;
+ scp->proc = NULL;
+ scp->smode.mode = VT_AUTO;
+ scp->history = NULL;
+ scp->history_pos = 0;
+ scp->history_size = 0;
+
+ mtx_init(&scp->scr_lock, "scrlock", NULL, MTX_SPIN);
+}
+
+int
+sc_init_emulator(scr_stat *scp, char *name)
+{
+ sc_term_sw_t *sw;
+ sc_rndr_sw_t *rndr;
+ void *p;
+ int error;
+
+ if (name == NULL) /* if no name is given, use the current emulator */
+ sw = scp->tsw;
+ else /* ...otherwise find the named emulator */
+ sw = sc_term_match(name);
+ if (sw == NULL)
+ return EINVAL;
+
+ rndr = NULL;
+ if (strcmp(sw->te_renderer, "*") != 0) {
+ rndr = sc_render_match(scp, sw->te_renderer,
+ scp->status & (GRAPHICS_MODE | PIXEL_MODE));
+ }
+ if (rndr == NULL) {
+ rndr = sc_render_match(scp, scp->sc->adp->va_name,
+ scp->status & (GRAPHICS_MODE | PIXEL_MODE));
+ if (rndr == NULL)
+ return ENODEV;
+ }
+
+ if (sw == scp->tsw) {
+ error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
+ scp->rndr = rndr;
+ scp->rndr->init(scp);
+ sc_clear_screen(scp);
+ /* assert(error == 0); */
+ return error;
+ }
+
+ if (sc_malloc && (sw->te_size > 0))
+ p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
+ else
+ p = NULL;
+ error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
+ if (error)
+ return error;
+
+ if (scp->tsw)
+ (*scp->tsw->te_term)(scp, &scp->ts);
+ if (scp->ts != NULL)
+ free(scp->ts, M_DEVBUF);
+ scp->tsw = sw;
+ scp->ts = p;
+ scp->rndr = rndr;
+ scp->rndr->init(scp);
+
+ /* XXX */
+ (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
+ sc_clear_screen(scp);
+
+ return 0;
+}
+
+/*
+ * scgetc(flags) - get character from keyboard.
+ * If flags & SCGETC_CN, then avoid harmful side effects.
+ * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
+ * return NOKEY if there is nothing there.
+ */
+static u_int
+scgetc(sc_softc_t *sc, u_int flags)
+{
+ scr_stat *scp;
+#ifndef SC_NO_HISTORY
+ struct tty *tp;
+#endif
+ u_int c;
+ int this_scr;
+ int f;
+ int i;
+
+ if (sc->kbd == NULL)
+ return NOKEY;
+
+next_code:
+#if 1
+ /* I don't like this, but... XXX */
+ if (flags & SCGETC_CN)
+ sccnupdate(sc->cur_scp);
+#endif
+ scp = sc->cur_scp;
+ /* first see if there is something in the keyboard port */
+ for (;;) {
+ c = kbdd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
+ if (c == ERRKEY) {
+ if (!(flags & SCGETC_CN))
+ sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
+ } else if (c == NOKEY)
+ return c;
+ else
+ break;
+ }
+
+ /* make screensaver happy */
+ if (!(c & RELKEY))
+ sc_touch_scrn_saver();
+
+ if (!(flags & SCGETC_CN))
+ random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD);
+
+ if (scp->kbd_mode != K_XLATE)
+ return KEYCHAR(c);
+
+ /* if scroll-lock pressed allow history browsing */
+ if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
+
+ scp->status &= ~CURSOR_ENABLED;
+ sc_remove_cursor_image(scp);
+
+#ifndef SC_NO_HISTORY
+ if (!(scp->status & BUFFER_SAVED)) {
+ scp->status |= BUFFER_SAVED;
+ sc_hist_save(scp);
+ }
+ switch (c) {
+ /* FIXME: key codes */
+ case SPCLKEY | FKEY | F(49): /* home key */
+ sc_remove_cutmarking(scp);
+ sc_hist_home(scp);
+ goto next_code;
+
+ case SPCLKEY | FKEY | F(57): /* end key */
+ sc_remove_cutmarking(scp);
+ sc_hist_end(scp);
+ goto next_code;
+
+ case SPCLKEY | FKEY | F(50): /* up arrow key */
+ sc_remove_cutmarking(scp);
+ if (sc_hist_up_line(scp))
+ if (!(flags & SCGETC_CN))
+ sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
+ goto next_code;
+
+ case SPCLKEY | FKEY | F(58): /* down arrow key */
+ sc_remove_cutmarking(scp);
+ if (sc_hist_down_line(scp))
+ if (!(flags & SCGETC_CN))
+ sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
+ goto next_code;
+
+ case SPCLKEY | FKEY | F(51): /* page up key */
+ sc_remove_cutmarking(scp);
+ for (i=0; i<scp->ysize; i++)
+ if (sc_hist_up_line(scp)) {
+ if (!(flags & SCGETC_CN))
+ sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
+ break;
+ }
+ goto next_code;
+
+ case SPCLKEY | FKEY | F(59): /* page down key */
+ sc_remove_cutmarking(scp);
+ for (i=0; i<scp->ysize; i++)
+ if (sc_hist_down_line(scp)) {
+ if (!(flags & SCGETC_CN))
+ sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
+ break;
+ }
+ goto next_code;
+ }
+#endif /* SC_NO_HISTORY */
+ }
+
+ /*
+ * Process and consume special keys here. Return a plain char code
+ * or a char code with the META flag or a function key code.
+ */
+ if (c & RELKEY) {
+ /* key released */
+ /* goto next_code */
+ } else {
+ /* key pressed */
+ if (c & SPCLKEY) {
+ c &= ~SPCLKEY;
+ switch (KEYCHAR(c)) {
+ /* LOCKING KEYS */
+ case NLK: case CLK: case ALK:
+ break;
+ case SLK:
+ kbdd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
+ if (f & SLKED) {
+ scp->status |= SLKED;
+ } else {
+ if (scp->status & SLKED) {
+ scp->status &= ~SLKED;
+#ifndef SC_NO_HISTORY
+ if (scp->status & BUFFER_SAVED) {
+ if (!sc_hist_restore(scp))
+ sc_remove_cutmarking(scp);
+ scp->status &= ~BUFFER_SAVED;
+ scp->status |= CURSOR_ENABLED;
+ sc_draw_cursor_image(scp);
+ }
+ tp = SC_DEV(sc, scp->index);
+ if (!kdb_active && tty_opened(tp))
+ sctty_outwakeup(tp);
+#endif
+ }
+ }
+ break;
+
+ case PASTE:
+#ifndef SC_NO_CUTPASTE
+ sc_mouse_paste(scp);
+#endif
+ break;
+
+ /* NON-LOCKING KEYS */
+ case NOP:
+ case LSH: case RSH: case LCTR: case RCTR:
+ case LALT: case RALT: case ASH: case META:
+ break;
+
+ case BTAB:
+ if (!(sc->flags & SC_SCRN_BLANKED))
+ return c;
+ break;
+
+ case SPSC:
+#ifdef DEV_SPLASH
+ /* force activatation/deactivation of the screen saver */
+ if (!(sc->flags & SC_SCRN_BLANKED)) {
+ run_scrn_saver = TRUE;
+ sc->scrn_time_stamp -= scrn_blank_time;
+ }
+ if (cold) {
+ /*
+ * While devices are being probed, the screen saver need
+ * to be invoked explictly. XXX
+ */
+ if (sc->flags & SC_SCRN_BLANKED) {
+ scsplash_stick(FALSE);
+ stop_scrn_saver(sc, current_saver);
+ } else {
+ if (!ISGRAPHSC(scp)) {
+ scsplash_stick(TRUE);
+ (*current_saver)(sc, TRUE);
+ }
+ }
+ }
+#endif /* DEV_SPLASH */
+ break;
+
+ case RBT:
+#ifndef SC_DISABLE_REBOOT
+ if (enable_reboot)
+ shutdown_nice(0);
+#endif
+ break;
+
+ case HALT:
+#ifndef SC_DISABLE_REBOOT
+ if (enable_reboot)
+ shutdown_nice(RB_HALT);
+#endif
+ break;
+
+ case PDWN:
+#ifndef SC_DISABLE_REBOOT
+ if (enable_reboot)
+ shutdown_nice(RB_HALT|RB_POWEROFF);
+#endif
+ break;
+
+ case SUSP:
+ power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
+ break;
+ case STBY:
+ power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
+ break;
+
+ case DBG:
+#ifndef SC_DISABLE_KDBKEY
+ if (enable_kdbkey)
+ kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
+#endif
+ break;
+
+ case PNC:
+ if (enable_panic_key)
+ panic("Forced by the panic key");
+ break;
+
+ case NEXT:
+ this_scr = scp->index;
+ for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
+ sc->first_vty + i != this_scr;
+ i = (i + 1)%sc->vtys) {
+ struct tty *tp = SC_DEV(sc, sc->first_vty + i);
+ if (tty_opened(tp)) {
+ sc_switch_scr(scp->sc, sc->first_vty + i);
+ break;
+ }
+ }
+ break;
+
+ case PREV:
+ this_scr = scp->index;
+ for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
+ sc->first_vty + i != this_scr;
+ i = (i + sc->vtys - 1)%sc->vtys) {
+ struct tty *tp = SC_DEV(sc, sc->first_vty + i);
+ if (tty_opened(tp)) {
+ sc_switch_scr(scp->sc, sc->first_vty + i);
+ break;
+ }
+ }
+ break;
+
+ default:
+ if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
+ sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
+ break;
+ }
+ /* assert(c & FKEY) */
+ if (!(sc->flags & SC_SCRN_BLANKED))
+ return c;
+ break;
+ }
+ /* goto next_code */
+ } else {
+ /* regular keys (maybe MKEY is set) */
+ if (!(sc->flags & SC_SCRN_BLANKED))
+ return c;
+ }
+ }
+
+ goto next_code;
+}
+
+static int
+sctty_mmap(struct tty *tp, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
+{
+ scr_stat *scp;
+
+ scp = sc_get_stat(tp);
+ if (scp != scp->sc->cur_scp)
+ return -1;
+ return vidd_mmap(scp->sc->adp, offset, paddr, nprot);
+}
+
+static int
+save_kbd_state(scr_stat *scp)
+{
+ int state;
+ int error;
+
+ error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ if (error == 0) {
+ scp->status &= ~LOCK_MASK;
+ scp->status |= state;
+ }
+ return error;
+}
+
+static int
+update_kbd_state(scr_stat *scp, int new_bits, int mask)
+{
+ int state;
+ int error;
+
+ if (mask != LOCK_MASK) {
+ error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ if (error)
+ return error;
+ state &= ~mask;
+ state |= new_bits & mask;
+ } else {
+ state = new_bits & LOCK_MASK;
+ }
+ error = kbdd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+}
+
+static int
+update_kbd_leds(scr_stat *scp, int which)
+{
+ int error;
+
+ which &= LOCK_MASK;
+ error = kbdd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+}
+
+int
+set_mode(scr_stat *scp)
+{
+ video_info_t info;
+
+ /* reject unsupported mode */
+ if (vidd_get_info(scp->sc->adp, scp->mode, &info))
+ return 1;
+
+ /* if this vty is not currently showing, do nothing */
+ if (scp != scp->sc->cur_scp)
+ return 0;
+
+ /* setup video hardware for the given mode */
+ vidd_set_mode(scp->sc->adp, scp->mode);
+ scp->rndr->init(scp);
+#ifndef __sparc64__
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
+ (void *)scp->sc->adp->va_window, FALSE);
+#endif
+
+#ifndef SC_NO_FONT_LOADING
+ /* load appropriate font */
+ if (!(scp->status & GRAPHICS_MODE)) {
+ if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
+ if (scp->font_size < 14) {
+ if (scp->sc->fonts_loaded & FONT_8)
+ sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
+ } else if (scp->font_size >= 16) {
+ if (scp->sc->fonts_loaded & FONT_16)
+ sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
+ } else {
+ if (scp->sc->fonts_loaded & FONT_14)
+ sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
+ }
+ /*
+ * FONT KLUDGE:
+ * This is an interim kludge to display correct font.
+ * Always use the font page #0 on the video plane 2.
+ * Somehow we cannot show the font in other font pages on
+ * some video cards... XXX
+ */
+ sc_show_font(scp, 0);
+ }
+ mark_all(scp);
+ }
+#endif /* !SC_NO_FONT_LOADING */
+
+ sc_set_border(scp, scp->border);
+ sc_set_cursor_image(scp);
+
+ return 0;
+}
+
+void
+sc_set_border(scr_stat *scp, int color)
+{
+ SC_VIDEO_LOCK(scp->sc);
+ (*scp->rndr->draw_border)(scp, color);
+ SC_VIDEO_UNLOCK(scp->sc);
+}
+
+#ifndef SC_NO_FONT_LOADING
+void
+sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
+ int base, int count)
+{
+ sc_softc_t *sc;
+
+ sc = scp->sc;
+ sc->font_loading_in_progress = TRUE;
+ vidd_load_font(sc->adp, page, size, width, buf, base, count);
+ sc->font_loading_in_progress = FALSE;
+}
+
+void
+sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
+ int base, int count)
+{
+ sc_softc_t *sc;
+
+ sc = scp->sc;
+ sc->font_loading_in_progress = TRUE;
+ vidd_save_font(sc->adp, page, size, width, buf, base, count);
+ sc->font_loading_in_progress = FALSE;
+}
+
+void
+sc_show_font(scr_stat *scp, int page)
+{
+ vidd_show_font(scp->sc->adp, page);
+}
+#endif /* !SC_NO_FONT_LOADING */
+
+void
+sc_paste(scr_stat *scp, const u_char *p, int count)
+{
+ struct tty *tp;
+ u_char *rmap;
+
+ tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
+ if (!tty_opened(tp))
+ return;
+ rmap = scp->sc->scr_rmap;
+ for (; count > 0; --count)
+ ttydisc_rint(tp, rmap[*p++], 0);
+ ttydisc_rint_done(tp);
+}
+
+void
+sc_respond(scr_stat *scp, const u_char *p, int count)
+{
+ struct tty *tp;
+
+ tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
+ if (!tty_opened(tp))
+ return;
+ for (; count > 0; --count)
+ ttydisc_rint(tp, *p++, 0);
+#if 0
+ /* XXX: we can't call ttydisc_rint_done() here! */
+ ttydisc_rint_done(tp);
+#endif
+}
+
+void
+sc_bell(scr_stat *scp, int pitch, int duration)
+{
+ if (cold || shutdown_in_progress || !enable_bell)
+ return;
+
+ if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
+ return;
+
+ if (scp->sc->flags & SC_VISUAL_BELL) {
+ if (scp->sc->blink_in_progress)
+ return;
+ scp->sc->blink_in_progress = 3;
+ if (scp != scp->sc->cur_scp)
+ scp->sc->blink_in_progress += 2;
+ blink_screen(scp->sc->cur_scp);
+ } else if (duration != 0 && pitch != 0) {
+ if (scp != scp->sc->cur_scp)
+ pitch *= 2;
+ sysbeep(1193182 / pitch, duration);
+ }
+}
+
+static void
+blink_screen(void *arg)
+{
+ scr_stat *scp = arg;
+ struct tty *tp;
+
+ if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
+ scp->sc->blink_in_progress = 0;
+ mark_all(scp);
+ tp = SC_DEV(scp->sc, scp->index);
+ if (tty_opened(tp))
+ sctty_outwakeup(tp);
+ if (scp->sc->delayed_next_scr)
+ sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
+ }
+ else {
+ (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
+ scp->sc->blink_in_progress & 1);
+ scp->sc->blink_in_progress--;
+ timeout(blink_screen, scp, hz / 10);
+ }
+}
+
+/*
+ * Until sc_attach_unit() gets called no dev structures will be available
+ * to store the per-screen current status. This is the case when the
+ * kernel is initially booting and needs access to its console. During
+ * this early phase of booting the console's current status is kept in
+ * one statically defined scr_stat structure, and any pointers to the
+ * dev structures will be NULL.
+ */
+
+static scr_stat *
+sc_get_stat(struct tty *tp)
+{
+ if (tp == NULL)
+ return (&main_console);
+ return (SC_STAT(tp));
+}
+
+/*
+ * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
+ * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
+ * any keyboard.
+ */
+
+static int
+sc_allocate_keyboard(sc_softc_t *sc, int unit)
+{
+ int idx0, idx;
+ keyboard_t *k0, *k;
+ keyboard_info_t ki;
+
+ idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
+ if (idx0 != -1) {
+ k0 = kbd_get_keyboard(idx0);
+
+ for (idx = kbd_find_keyboard2("*", -1, 0);
+ idx != -1;
+ idx = kbd_find_keyboard2("*", -1, idx + 1)) {
+ k = kbd_get_keyboard(idx);
+
+ if (idx == idx0 || KBD_IS_BUSY(k))
+ continue;
+
+ bzero(&ki, sizeof(ki));
+ strcpy(ki.kb_name, k->kb_name);
+ ki.kb_unit = k->kb_unit;
+
+ kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
+ }
+ } else
+ idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);
+
+ return (idx0);
+}
diff --git a/sys/dev/syscons/syscons.h b/sys/dev/syscons/syscons.h
new file mode 100644
index 000000000000..c0ed6c1fd642
--- /dev/null
+++ b/sys/dev/syscons/syscons.h
@@ -0,0 +1,673 @@
+/*-
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sascha Wildner <saw@online.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEV_SYSCONS_SYSCONS_H_
+#define _DEV_SYSCONS_SYSCONS_H_
+
+#include <sys/lock.h>
+#include <sys/mutex.h>
+
+/* machine-dependent part of the header */
+
+#ifdef PC98
+#include <pc98/cbus/sc_machdep.h>
+#elif defined(__i386__)
+/* nothing for the moment */
+#endif
+
+/* default values for configuration options */
+
+#ifndef MAXCONS
+#define MAXCONS 16
+#endif
+
+#ifdef SC_NO_SYSMOUSE
+#undef SC_NO_CUTPASTE
+#define SC_NO_CUTPASTE 1
+#endif
+
+#ifdef SC_NO_MODE_CHANGE
+#undef SC_PIXEL_MODE
+#endif
+
+/* Always load font data if the pixel (raster text) mode is to be used. */
+#ifdef SC_PIXEL_MODE
+#undef SC_NO_FONT_LOADING
+#endif
+
+/*
+ * If font data is not available, the `arrow'-shaped mouse cursor cannot
+ * be drawn. Use the alternative drawing method.
+ */
+#ifdef SC_NO_FONT_LOADING
+#undef SC_ALT_MOUSE_IMAGE
+#define SC_ALT_MOUSE_IMAGE 1
+#endif
+
+#ifndef SC_CURSOR_CHAR
+#define SC_CURSOR_CHAR (0x07)
+#endif
+
+#ifndef SC_MOUSE_CHAR
+#define SC_MOUSE_CHAR (0xd0)
+#endif
+
+#if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
+#undef SC_CURSOR_CHAR
+#define SC_CURSOR_CHAR (SC_MOUSE_CHAR + 4)
+#endif
+
+#ifndef SC_DEBUG_LEVEL
+#define SC_DEBUG_LEVEL 0
+#endif
+
+#define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p
+
+#ifndef __sparc64__
+#define SC_DRIVER_NAME "sc"
+#else
+/*
+ * Use a different driver name on sparc64 so it does not get confused
+ * with the system controller devices which are also termed 'sc' in OFW.
+ */
+#define SC_DRIVER_NAME "syscons"
+#endif
+#define SC_VTY(dev) (((sc_ttysoftc *)tty_softc(tp))->st_index)
+#define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty])
+#define SC_STAT(tp) (*((scr_stat **)&((sc_ttysoftc *)tty_softc(tp))->st_stat))
+
+/* printable chars */
+#ifndef PRINTABLE
+#define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
+ || (ch) < 0x07)
+#endif
+
+/* macros for "intelligent" screen update */
+#define mark_for_update(scp, x) {\
+ if ((x) < scp->start) scp->start = (x);\
+ else if ((x) > scp->end) scp->end = (x);\
+ }
+#define mark_all(scp) {\
+ scp->start = 0;\
+ scp->end = scp->xsize * scp->ysize - 1;\
+ }
+
+/* vty status flags (scp->status) */
+#define UNKNOWN_MODE 0x00010 /* unknown video mode */
+#define SWITCH_WAIT_REL 0x00080 /* waiting for vty release */
+#define SWITCH_WAIT_ACQ 0x00100 /* waiting for vty ack */
+#define BUFFER_SAVED 0x00200 /* vty buffer is saved */
+#define CURSOR_ENABLED 0x00400 /* text cursor is enabled */
+#define MOUSE_MOVED 0x01000 /* mouse cursor has moved */
+#define MOUSE_CUTTING 0x02000 /* mouse cursor is cutting text */
+#define MOUSE_VISIBLE 0x04000 /* mouse cursor is showing */
+#define GRAPHICS_MODE 0x08000 /* vty is in a graphics mode */
+#define PIXEL_MODE 0x10000 /* vty is in a raster text mode */
+#define SAVER_RUNNING 0x20000 /* screen saver is running */
+#define VR_CURSOR_BLINK 0x40000 /* blinking text cursor */
+#define VR_CURSOR_ON 0x80000 /* text cursor is on */
+#define MOUSE_HIDDEN 0x100000 /* mouse cursor is temporarily hidden */
+
+/* misc defines */
+#define FALSE 0
+#define TRUE 1
+
+/*
+ The following #defines are hard-coded for a maximum text
+ resolution corresponding to a maximum framebuffer
+ resolution of 1600x1200 with an 8x8 font...
+*/
+#define COL 200
+#define ROW 150
+
+#define PCBURST 128
+
+#ifndef BELL_DURATION
+#define BELL_DURATION ((5 * hz + 99) / 100)
+#define BELL_PITCH 800
+#endif
+
+/* virtual terminal buffer */
+typedef struct sc_vtb {
+ int vtb_flags;
+#define VTB_VALID (1 << 0)
+#define VTB_ALLOCED (1 << 1)
+ int vtb_type;
+#define VTB_INVALID 0
+#define VTB_MEMORY 1
+#define VTB_FRAMEBUFFER 2
+#define VTB_RINGBUFFER 3
+ int vtb_cols;
+ int vtb_rows;
+ int vtb_size;
+ vm_offset_t vtb_buffer;
+ int vtb_tail; /* valid for VTB_RINGBUFFER only */
+} sc_vtb_t;
+
+/* text cursor attributes */
+struct cursor_attr {
+ int flags;
+ int base;
+ int height;
+};
+
+/* softc */
+
+struct keyboard;
+struct video_adapter;
+struct scr_stat;
+struct tty;
+
+typedef struct sc_softc {
+ int unit; /* unit # */
+ int config; /* configuration flags */
+#define SC_VESA800X600 (1 << 7)
+#define SC_AUTODETECT_KBD (1 << 8)
+#define SC_KERNEL_CONSOLE (1 << 9)
+
+ int flags; /* status flags */
+#define SC_VISUAL_BELL (1 << 0)
+#define SC_QUIET_BELL (1 << 1)
+#if 0 /* not used anymore */
+#define SC_BLINK_CURSOR (1 << 2)
+#define SC_CHAR_CURSOR (1 << 3)
+#endif
+#define SC_MOUSE_ENABLED (1 << 4)
+#define SC_SCRN_IDLE (1 << 5)
+#define SC_SCRN_BLANKED (1 << 6)
+#define SC_SAVER_FAILED (1 << 7)
+#define SC_SCRN_VTYLOCK (1 << 8)
+
+#define SC_INIT_DONE (1 << 16)
+#define SC_SPLASH_SCRN (1 << 17)
+
+ int keyboard; /* -1 if unavailable */
+ struct keyboard *kbd;
+
+ int adapter;
+ struct video_adapter *adp;
+ int initial_mode; /* initial video mode */
+
+ int first_vty;
+ int vtys;
+ struct tty **dev;
+ struct scr_stat *cur_scp;
+ struct scr_stat *new_scp;
+ struct scr_stat *old_scp;
+ int delayed_next_scr;
+
+ char font_loading_in_progress;
+ char switch_in_progress;
+ char write_in_progress;
+ char blink_in_progress;
+ struct mtx video_mtx;
+
+ long scrn_time_stamp;
+
+ struct cursor_attr dflt_curs_attr;
+ struct cursor_attr curs_attr;
+
+ u_char scr_map[256];
+ u_char scr_rmap[256];
+
+#ifdef _SC_MD_SOFTC_DECLARED_
+ sc_md_softc_t md; /* machine dependent vars */
+#endif
+
+#ifndef SC_NO_PALETTE_LOADING
+ u_char palette[256*3];
+#endif
+
+#ifndef SC_NO_FONT_LOADING
+ int fonts_loaded;
+#define FONT_8 2
+#define FONT_14 4
+#define FONT_16 8
+#define FONT_22 8
+ u_char *font_8;
+ u_char *font_14;
+ u_char *font_16;
+ u_char *font_22;
+#endif
+
+ u_char cursor_char;
+ u_char mouse_char;
+
+} sc_softc_t;
+
+/* virtual screen */
+typedef struct scr_stat {
+ int index; /* index of this vty */
+ struct sc_softc *sc; /* pointer to softc */
+ struct sc_rndr_sw *rndr; /* renderer */
+#ifndef __sparc64__
+ sc_vtb_t scr;
+#endif
+ sc_vtb_t vtb;
+
+ int xpos; /* current X position */
+ int ypos; /* current Y position */
+ int xsize; /* X text size */
+ int ysize; /* Y text size */
+ int xpixel; /* X graphics size */
+ int ypixel; /* Y graphics size */
+ int xoff; /* X offset in pixel mode */
+ int yoff; /* Y offset in pixel mode */
+
+ u_char *font; /* current font */
+ int font_size; /* fontsize in Y direction */
+ int font_width; /* fontsize in X direction */
+
+ int start; /* modified area start */
+ int end; /* modified area end */
+
+ struct sc_term_sw *tsw;
+ void *ts;
+
+ int status; /* status (bitfield) */
+ int kbd_mode; /* keyboard I/O mode */
+
+ int cursor_pos; /* cursor buffer position */
+ int cursor_oldpos; /* cursor old buffer position */
+ u_short cursor_saveunder_char; /* saved char under cursor */
+ u_short cursor_saveunder_attr; /* saved attr under cursor */
+ struct cursor_attr dflt_curs_attr;
+ struct cursor_attr curr_curs_attr;
+ struct cursor_attr curs_attr;
+
+ int mouse_pos; /* mouse buffer position */
+ int mouse_oldpos; /* mouse old buffer position */
+ short mouse_xpos; /* mouse x coordinate */
+ short mouse_ypos; /* mouse y coordinate */
+ short mouse_oldxpos; /* mouse previous x coordinate */
+ short mouse_oldypos; /* mouse previous y coordinate */
+ short mouse_buttons; /* mouse buttons */
+ int mouse_cut_start; /* mouse cut start pos */
+ int mouse_cut_end; /* mouse cut end pos */
+ struct proc *mouse_proc; /* proc* of controlling proc */
+ pid_t mouse_pid; /* pid of controlling proc */
+ int mouse_signal; /* signal # to report with */
+
+ u_short bell_duration;
+ u_short bell_pitch;
+
+ u_char border; /* border color */
+ int mode; /* mode */
+ pid_t pid; /* pid of controlling proc */
+ struct proc *proc; /* proc* of controlling proc */
+ struct vt_mode smode; /* switch mode */
+
+ sc_vtb_t *history; /* circular history buffer */
+ int history_pos; /* position shown on screen */
+ int history_size; /* size of history buffer */
+
+ int splash_save_mode; /* saved mode for splash screen */
+ int splash_save_status; /* saved status for splash screen */
+ struct mtx scr_lock; /* mutex for sc_puts() */
+#ifdef _SCR_MD_STAT_DECLARED_
+ scr_md_stat_t md; /* machine dependent vars */
+#endif
+} scr_stat;
+
+/* TTY softc. */
+typedef struct sc_ttysoftc {
+ int st_index;
+ scr_stat *st_stat;
+} sc_ttysoftc;
+
+#ifndef SC_NORM_ATTR
+#define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
+#endif
+#ifndef SC_NORM_REV_ATTR
+#define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
+#endif
+#ifndef SC_KERNEL_CONS_ATTR
+#define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK)
+#endif
+#ifndef SC_KERNEL_CONS_REV_ATTR
+#define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
+#endif
+
+/* terminal emulator */
+
+#ifndef SC_DFLT_TERM
+#define SC_DFLT_TERM "*" /* any */
+#endif
+
+typedef int sc_term_init_t(scr_stat *scp, void **tcp, int code);
+#define SC_TE_COLD_INIT 0
+#define SC_TE_WARM_INIT 1
+typedef int sc_term_term_t(scr_stat *scp, void **tcp);
+typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len, int kernel);
+typedef int sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
+ caddr_t data, struct thread *td);
+typedef int sc_term_reset_t(scr_stat *scp, int code);
+#define SC_TE_HARD_RESET 0
+#define SC_TE_SOFT_RESET 1
+typedef void sc_term_default_attr_t(scr_stat *scp, int norm, int rev);
+typedef void sc_term_clear_t(scr_stat *scp);
+typedef void sc_term_notify_t(scr_stat *scp, int event);
+#define SC_TE_NOTIFY_VTSWITCH_IN 0
+#define SC_TE_NOTIFY_VTSWITCH_OUT 1
+typedef int sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
+
+typedef struct sc_term_sw {
+ LIST_ENTRY(sc_term_sw) link;
+ char *te_name; /* name of the emulator */
+ char *te_desc; /* description */
+ char *te_renderer; /* matching renderer */
+ size_t te_size; /* size of internal buffer */
+ int te_refcount; /* reference counter */
+ sc_term_init_t *te_init;
+ sc_term_term_t *te_term;
+ sc_term_puts_t *te_puts;
+ sc_term_ioctl_t *te_ioctl;
+ sc_term_reset_t *te_reset;
+ sc_term_default_attr_t *te_default_attr;
+ sc_term_clear_t *te_clear;
+ sc_term_notify_t *te_notify;
+ sc_term_input_t *te_input;
+} sc_term_sw_t;
+
+#define SCTERM_MODULE(name, sw) \
+ DATA_SET(scterm_set, sw); \
+ static int \
+ scterm_##name##_event(module_t mod, int type, void *data) \
+ { \
+ switch (type) { \
+ case MOD_LOAD: \
+ return sc_term_add(&sw); \
+ case MOD_UNLOAD: \
+ if (sw.te_refcount > 0) \
+ return EBUSY; \
+ return sc_term_remove(&sw); \
+ default: \
+ return EOPNOTSUPP; \
+ break; \
+ } \
+ return 0; \
+ } \
+ static moduledata_t scterm_##name##_mod = { \
+ "scterm-" #name, \
+ scterm_##name##_event, \
+ NULL, \
+ }; \
+ DECLARE_MODULE(scterm_##name, scterm_##name##_mod, \
+ SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
+
+/* renderer function table */
+typedef void vr_init_t(scr_stat *scp);
+typedef void vr_clear_t(scr_stat *scp, int c, int attr);
+typedef void vr_draw_border_t(scr_stat *scp, int color);
+typedef void vr_draw_t(scr_stat *scp, int from, int count, int flip);
+typedef void vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
+typedef void vr_draw_cursor_t(scr_stat *scp, int at, int blink,
+ int on, int flip);
+typedef void vr_blink_cursor_t(scr_stat *scp, int at, int flip);
+typedef void vr_set_mouse_t(scr_stat *scp);
+typedef void vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
+
+typedef struct sc_rndr_sw {
+ vr_init_t *init;
+ vr_clear_t *clear;
+ vr_draw_border_t *draw_border;
+ vr_draw_t *draw;
+ vr_set_cursor_t *set_cursor;
+ vr_draw_cursor_t *draw_cursor;
+ vr_blink_cursor_t *blink_cursor;
+ vr_set_mouse_t *set_mouse;
+ vr_draw_mouse_t *draw_mouse;
+} sc_rndr_sw_t;
+
+typedef struct sc_renderer {
+ char *name;
+ int mode;
+ sc_rndr_sw_t *rndrsw;
+ LIST_ENTRY(sc_renderer) link;
+} sc_renderer_t;
+
+#define RENDERER(name, mode, sw, set) \
+ static struct sc_renderer scrndr_##name##_##mode = { \
+ #name, mode, &sw \
+ }; \
+ DATA_SET(scrndr_set, scrndr_##name##_##mode); \
+ DATA_SET(set, scrndr_##name##_##mode)
+
+#define RENDERER_MODULE(name, set) \
+ SET_DECLARE(set, sc_renderer_t); \
+ static int \
+ scrndr_##name##_event(module_t mod, int type, void *data) \
+ { \
+ sc_renderer_t **list; \
+ int error = 0; \
+ switch (type) { \
+ case MOD_LOAD: \
+ SET_FOREACH(list, set) { \
+ error = sc_render_add(*list); \
+ if (error) \
+ break; \
+ } \
+ break; \
+ case MOD_UNLOAD: \
+ SET_FOREACH(list, set) { \
+ error = sc_render_remove(*list);\
+ if (error) \
+ break; \
+ } \
+ break; \
+ default: \
+ return EOPNOTSUPP; \
+ break; \
+ } \
+ return error; \
+ } \
+ static moduledata_t scrndr_##name##_mod = { \
+ "scrndr-" #name, \
+ scrndr_##name##_event, \
+ NULL, \
+ }; \
+ DECLARE_MODULE(scrndr_##name, scrndr_##name##_mod, \
+ SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
+
+typedef struct {
+ int cursor_start;
+ int cursor_end;
+ int shift_state;
+ int bell_pitch;
+} bios_values_t;
+
+/* other macros */
+#define ISTEXTSC(scp) (!((scp)->status \
+ & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
+#define ISGRAPHSC(scp) (((scp)->status \
+ & (UNKNOWN_MODE | GRAPHICS_MODE)))
+#define ISPIXELSC(scp) (((scp)->status \
+ & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
+ == PIXEL_MODE)
+#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
+
+#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
+#define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
+#define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
+
+#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
+
+#define SC_VIDEO_LOCKINIT(sc) \
+ mtx_init(&(sc)->video_mtx, "syscons video lock", NULL, \
+ MTX_SPIN | MTX_RECURSE);
+#define SC_VIDEO_LOCK(sc) \
+ do { \
+ if (!cold) \
+ mtx_lock_spin(&(sc)->video_mtx); \
+ } while(0)
+#define SC_VIDEO_UNLOCK(sc) \
+ do { \
+ if (!cold) \
+ mtx_unlock_spin(&(sc)->video_mtx); \
+ } while(0)
+
+/* syscons.c */
+extern int (*sc_user_ioctl)(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+
+int sc_probe_unit(int unit, int flags);
+int sc_attach_unit(int unit, int flags);
+
+int set_mode(scr_stat *scp);
+
+void sc_set_border(scr_stat *scp, int color);
+void sc_load_font(scr_stat *scp, int page, int size, int width,
+ u_char *font, int base, int count);
+void sc_save_font(scr_stat *scp, int page, int size, int width,
+ u_char *font, int base, int count);
+void sc_show_font(scr_stat *scp, int page);
+
+void sc_touch_scrn_saver(void);
+void sc_puts(scr_stat *scp, u_char *buf, int len, int kernel);
+void sc_draw_cursor_image(scr_stat *scp);
+void sc_remove_cursor_image(scr_stat *scp);
+void sc_set_cursor_image(scr_stat *scp);
+void sc_change_cursor_shape(scr_stat *scp, int flags,
+ int base, int height);
+int sc_clean_up(scr_stat *scp);
+int sc_switch_scr(sc_softc_t *sc, u_int next_scr);
+void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
+int sc_init_emulator(scr_stat *scp, char *name);
+void sc_paste(scr_stat *scp, const u_char *p, int count);
+void sc_respond(scr_stat *scp, const u_char *p, int count);
+void sc_bell(scr_stat *scp, int pitch, int duration);
+
+/* schistory.c */
+#ifndef SC_NO_HISTORY
+int sc_alloc_history_buffer(scr_stat *scp, int lines,
+ int prev_ysize, int wait);
+void sc_free_history_buffer(scr_stat *scp, int prev_ysize);
+void sc_hist_save(scr_stat *scp);
+#define sc_hist_save_one_line(scp, from) \
+ sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
+int sc_hist_restore(scr_stat *scp);
+void sc_hist_home(scr_stat *scp);
+void sc_hist_end(scr_stat *scp);
+int sc_hist_up_line(scr_stat *scp);
+int sc_hist_down_line(scr_stat *scp);
+int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+#endif /* SC_NO_HISTORY */
+
+/* scmouse.c */
+#ifndef SC_NO_CUTPASTE
+void sc_alloc_cut_buffer(scr_stat *scp, int wait);
+void sc_draw_mouse_image(scr_stat *scp);
+void sc_remove_mouse_image(scr_stat *scp);
+int sc_inside_cutmark(scr_stat *scp, int pos);
+void sc_remove_cutmarking(scr_stat *scp);
+void sc_remove_all_cutmarkings(sc_softc_t *scp);
+void sc_remove_all_mouse(sc_softc_t *scp);
+void sc_mouse_paste(scr_stat *scp);
+#else
+#define sc_draw_mouse_image(scp)
+#define sc_remove_mouse_image(scp)
+#define sc_inside_cutmark(scp, pos) FALSE
+#define sc_remove_cutmarking(scp)
+#define sc_remove_all_cutmarkings(scp)
+#define sc_remove_all_mouse(scp)
+#define sc_mouse_paste(scp)
+#endif /* SC_NO_CUTPASTE */
+#ifndef SC_NO_SYSMOUSE
+void sc_mouse_move(scr_stat *scp, int x, int y);
+int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+#endif /* SC_NO_SYSMOUSE */
+
+/* scvidctl.c */
+int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
+ int xsize, int ysize, int fontsize,
+ int font_width);
+int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
+int sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize,
+ int ysize, int fontsize, int font_width);
+int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+
+int sc_render_add(sc_renderer_t *rndr);
+int sc_render_remove(sc_renderer_t *rndr);
+sc_rndr_sw_t *sc_render_match(scr_stat *scp, char *name, int mode);
+
+/* scvtb.c */
+void sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
+ void *buffer, int wait);
+void sc_vtb_destroy(sc_vtb_t *vtb);
+size_t sc_vtb_size(int cols, int rows);
+void sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
+
+int sc_vtb_getc(sc_vtb_t *vtb, int at);
+int sc_vtb_geta(sc_vtb_t *vtb, int at);
+void sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
+vm_offset_t sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
+vm_offset_t sc_vtb_pointer(sc_vtb_t *vtb, int at);
+int sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
+
+#define sc_vtb_tail(vtb) ((vtb)->vtb_tail)
+#define sc_vtb_rows(vtb) ((vtb)->vtb_rows)
+#define sc_vtb_cols(vtb) ((vtb)->vtb_cols)
+
+void sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
+ int count);
+void sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
+ int count);
+void sc_vtb_seek(sc_vtb_t *vtb, int pos);
+void sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
+void sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
+void sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
+void sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
+
+/* sysmouse.c */
+int sysmouse_event(mouse_info_t *info);
+
+/* scterm.c */
+void sc_move_cursor(scr_stat *scp, int x, int y);
+void sc_clear_screen(scr_stat *scp);
+int sc_term_add(sc_term_sw_t *sw);
+int sc_term_remove(sc_term_sw_t *sw);
+sc_term_sw_t *sc_term_match(char *name);
+sc_term_sw_t *sc_term_match_by_number(int index);
+
+/* machine dependent functions */
+int sc_max_unit(void);
+sc_softc_t *sc_get_softc(int unit, int flags);
+sc_softc_t *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
+int sc_get_cons_priority(int *unit, int *flags);
+void sc_get_bios_values(bios_values_t *values);
+int sc_tone(int herz);
+
+#endif /* !_DEV_SYSCONS_SYSCONS_H_ */
diff --git a/sys/dev/syscons/sysmouse.c b/sys/dev/syscons/sysmouse.c
new file mode 100644
index 000000000000..4e787efbbe51
--- /dev/null
+++ b/sys/dev/syscons/sysmouse.c
@@ -0,0 +1,249 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_syscons.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/priv.h>
+#include <sys/serial.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/consio.h>
+#include <sys/mouse.h>
+
+#include <dev/syscons/syscons.h>
+
+#ifndef SC_NO_SYSMOUSE
+
+/* local variables */
+static struct tty *sysmouse_tty;
+static int mouse_level; /* sysmouse protocol level */
+static mousestatus_t mouse_status;
+
+static void
+smdev_close(struct tty *tp)
+{
+ mouse_level = 0;
+}
+
+static int
+smdev_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+{
+ mousehw_t *hw;
+ mousemode_t *mode;
+
+ switch (cmd) {
+
+ case MOUSE_GETHWINFO: /* get device information */
+ hw = (mousehw_t *)data;
+ hw->buttons = 10; /* XXX unknown */
+ hw->iftype = MOUSE_IF_SYSMOUSE;
+ hw->type = MOUSE_MOUSE;
+ hw->model = MOUSE_MODEL_GENERIC;
+ hw->hwid = 0;
+ return 0;
+
+ case MOUSE_GETMODE: /* get protocol/mode */
+ mode = (mousemode_t *)data;
+ mode->level = mouse_level;
+ switch (mode->level) {
+ case 0: /* emulate MouseSystems protocol */
+ mode->protocol = MOUSE_PROTO_MSC;
+ mode->rate = -1; /* unknown */
+ mode->resolution = -1; /* unknown */
+ mode->accelfactor = 0; /* disabled */
+ mode->packetsize = MOUSE_MSC_PACKETSIZE;
+ mode->syncmask[0] = MOUSE_MSC_SYNCMASK;
+ mode->syncmask[1] = MOUSE_MSC_SYNC;
+ break;
+
+ case 1: /* sysmouse protocol */
+ mode->protocol = MOUSE_PROTO_SYSMOUSE;
+ mode->rate = -1;
+ mode->resolution = -1;
+ mode->accelfactor = 0;
+ mode->packetsize = MOUSE_SYS_PACKETSIZE;
+ mode->syncmask[0] = MOUSE_SYS_SYNCMASK;
+ mode->syncmask[1] = MOUSE_SYS_SYNC;
+ break;
+ }
+ return 0;
+
+ case MOUSE_SETMODE: /* set protocol/mode */
+ mode = (mousemode_t *)data;
+ if (mode->level == -1)
+ ; /* don't change the current setting */
+ else if ((mode->level < 0) || (mode->level > 1))
+ return EINVAL;
+ else
+ mouse_level = mode->level;
+ return 0;
+
+ case MOUSE_GETLEVEL: /* get operation level */
+ *(int *)data = mouse_level;
+ return 0;
+
+ case MOUSE_SETLEVEL: /* set operation level */
+ if ((*(int *)data < 0) || (*(int *)data > 1))
+ return EINVAL;
+ mouse_level = *(int *)data;
+ return 0;
+
+ case MOUSE_GETSTATUS: /* get accumulated mouse events */
+ *(mousestatus_t *)data = mouse_status;
+ mouse_status.flags = 0;
+ mouse_status.obutton = mouse_status.button;
+ mouse_status.dx = 0;
+ mouse_status.dy = 0;
+ mouse_status.dz = 0;
+ return 0;
+
+#ifdef notyet
+ case MOUSE_GETVARS: /* get internal mouse variables */
+ case MOUSE_SETVARS: /* set internal mouse variables */
+ return ENODEV;
+#endif
+
+ case MOUSE_READSTATE: /* read status from the device */
+ case MOUSE_READDATA: /* read data from the device */
+ return ENODEV;
+ }
+
+ return (ENOIOCTL);
+}
+
+static int
+smdev_param(struct tty *tp, struct termios *t)
+{
+
+ /*
+ * Set the output baud rate to zero. The mouse device supports
+ * no output, so we don't want to waste buffers.
+ */
+ t->c_ispeed = TTYDEF_SPEED;
+ t->c_ospeed = B0;
+
+ return (0);
+}
+
+static struct ttydevsw smdev_ttydevsw = {
+ .tsw_flags = TF_NOPREFIX,
+ .tsw_close = smdev_close,
+ .tsw_ioctl = smdev_ioctl,
+ .tsw_param = smdev_param,
+};
+
+static void
+sm_attach_mouse(void *unused)
+{
+ sysmouse_tty = tty_alloc(&smdev_ttydevsw, NULL);
+ tty_makedev(sysmouse_tty, NULL, "sysmouse");
+}
+
+SYSINIT(sysmouse, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sm_attach_mouse, NULL);
+
+int
+sysmouse_event(mouse_info_t *info)
+{
+ /* MOUSE_BUTTON?DOWN -> MOUSE_MSC_BUTTON?UP */
+ static int butmap[8] = {
+ MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
+ MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
+ MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
+ MOUSE_MSC_BUTTON3UP,
+ MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
+ MOUSE_MSC_BUTTON2UP,
+ MOUSE_MSC_BUTTON1UP,
+ 0,
+ };
+ u_char buf[8];
+ int x, y, z;
+ int i, flags = 0;
+
+ tty_lock(sysmouse_tty);
+
+ switch (info->operation) {
+ case MOUSE_ACTION:
+ mouse_status.button = info->u.data.buttons;
+ /* FALL THROUGH */
+ case MOUSE_MOTION_EVENT:
+ x = info->u.data.x;
+ y = info->u.data.y;
+ z = info->u.data.z;
+ break;
+ case MOUSE_BUTTON_EVENT:
+ x = y = z = 0;
+ if (info->u.event.value > 0)
+ mouse_status.button |= info->u.event.id;
+ else
+ mouse_status.button &= ~info->u.event.id;
+ break;
+ default:
+ goto done;
+ }
+
+ mouse_status.dx += x;
+ mouse_status.dy += y;
+ mouse_status.dz += z;
+ mouse_status.flags |= ((x || y || z) ? MOUSE_POSCHANGED : 0)
+ | (mouse_status.obutton ^ mouse_status.button);
+ flags = mouse_status.flags;
+ if (flags == 0 || !tty_opened(sysmouse_tty))
+ goto done;
+
+ /* the first five bytes are compatible with MouseSystems' */
+ buf[0] = MOUSE_MSC_SYNC
+ | butmap[mouse_status.button & MOUSE_STDBUTTONS];
+ x = imax(imin(x, 255), -256);
+ buf[1] = x >> 1;
+ buf[3] = x - buf[1];
+ y = -imax(imin(y, 255), -256);
+ buf[2] = y >> 1;
+ buf[4] = y - buf[2];
+ for (i = 0; i < MOUSE_MSC_PACKETSIZE; ++i)
+ ttydisc_rint(sysmouse_tty, buf[i], 0);
+ if (mouse_level >= 1) {
+ /* extended part */
+ z = imax(imin(z, 127), -128);
+ buf[5] = (z >> 1) & 0x7f;
+ buf[6] = (z - (z >> 1)) & 0x7f;
+ /* buttons 4-10 */
+ buf[7] = (~mouse_status.button >> 3) & 0x7f;
+ for (i = MOUSE_MSC_PACKETSIZE; i < MOUSE_SYS_PACKETSIZE; ++i)
+ ttydisc_rint(sysmouse_tty, buf[i], 0);
+ }
+ ttydisc_rint_done(sysmouse_tty);
+
+done: tty_unlock(sysmouse_tty);
+ return (flags);
+}
+
+#endif /* !SC_NO_SYSMOUSE */
diff --git a/sys/dev/syscons/teken/Makefile b/sys/dev/syscons/teken/Makefile
new file mode 100644
index 000000000000..cbdd12bb509a
--- /dev/null
+++ b/sys/dev/syscons/teken/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+PROG= teken_demo
+SRCS= teken_demo.c teken.c teken_state.h
+CLEANFILES= teken_state.h teken.log
+LDADD= -lncurses -lutil
+NO_MAN=
+WARNS?= 6
+
+teken_state.h: gensequences sequences
+ awk -f gensequences sequences > ${.TARGET}
+
+.include <bsd.prog.mk>
diff --git a/sys/dev/syscons/teken/gensequences b/sys/dev/syscons/teken/gensequences
new file mode 100644
index 000000000000..86c7979c7309
--- /dev/null
+++ b/sys/dev/syscons/teken/gensequences
@@ -0,0 +1,157 @@
+#!/usr/bin/awk -f
+
+#-
+# Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+function die(msg) {
+ print msg;
+ exit 1;
+}
+
+function cchar(str) {
+ if (str == "^[")
+ return "\\x1B";
+
+ return str;
+}
+
+BEGIN {
+FS = "\t+"
+
+while (getline > 0) {
+ if (NF == 0 || $1 ~ /^#/)
+ continue;
+
+ if (NF != 3 && NF != 4)
+ die("Invalid line layout: " NF " columns");
+
+ split($3, sequence, " +");
+ nsequences = 0;
+ for (s in sequence)
+ nsequences++;
+
+ prefix = "";
+ l_prefix_name[""] = "teken_state_init";
+ for (i = 1; i < nsequences; i++) {
+ n = prefix sequence[i];
+ l_prefix_parent[n] = prefix;
+ l_prefix_suffix[n] = sequence[i];
+ if (!l_prefix_name[n])
+ l_prefix_name[n] = "teken_state_" ++npr;
+ prefix = n;
+ }
+
+ suffix = sequence[nsequences];
+ cmd = prefix suffix;
+
+ # Fill lists
+ if (l_cmd_name[cmd] != "")
+ die(cmd " already exists");
+ l_cmd_prefix[cmd] = prefix;
+ l_cmd_suffix[cmd] = suffix;
+ l_cmd_args[cmd] = $4;
+ l_cmd_abbr[cmd] = $1;
+ l_cmd_name[cmd] = $2;
+ l_cmd_c_name[cmd] = "teken_subr_" tolower($2);
+ gsub(" ", "_", l_cmd_c_name[cmd]);
+
+ if ($4 != "")
+ l_prefix_numbercmds[prefix]++;
+}
+
+print "/* Generated file. Do not edit. */";
+print "";
+
+for (p in l_prefix_name) {
+ if (l_prefix_name[p] != "teken_state_init")
+ print "static teken_state_t " l_prefix_name[p] ";";
+}
+
+for (p in l_prefix_name) {
+ print "";
+ print "/* '" p "' */";
+ print "static void";
+ print l_prefix_name[p] "(teken_t *t, teken_char_t c)";
+ print "{";
+
+ if (l_prefix_numbercmds[p] > 0) {
+ print "";
+ print "\tif (teken_state_numbers(t, c))";
+ print "\t\treturn;";
+ }
+
+ print "";
+ print "\tswitch (c) {";
+ for (c in l_cmd_prefix) {
+ if (l_cmd_prefix[c] != p)
+ continue;
+
+ print "\tcase '" cchar(l_cmd_suffix[c]) "': /* " l_cmd_abbr[c] ": " l_cmd_name[c] " */";
+
+ if (l_cmd_args[c] == "v") {
+ print "\t\t" l_cmd_c_name[c] "(t, t->t_curnum, t->t_nums);";
+ } else {
+ printf "\t\t%s(t", l_cmd_c_name[c];
+ split(l_cmd_args[c], args, " ");
+ for (a = 1; args[a] != ""; a++) {
+ if (args[a] == "n")
+ printf ", (t->t_curnum < %d || t->t_nums[%d] == 0) ? 1 : t->t_nums[%d]", a, (a - 1), (a - 1);
+ else if (args[a] == "r")
+ printf ", t->t_curnum < %d ? 0 : t->t_nums[%d]", a, (a - 1);
+ else
+ die("Invalid argument type: " args[a]);
+ }
+ print ");";
+ }
+ print "\t\tbreak;";
+ }
+ for (pc in l_prefix_parent) {
+ if (l_prefix_parent[pc] != p)
+ continue;
+ print "\tcase '" cchar(l_prefix_suffix[pc]) "':";
+ print "\t\tteken_state_switch(t, " l_prefix_name[pc] ");";
+ print "\t\treturn;";
+ }
+
+ print "\tdefault:";
+ if (l_prefix_name[p] == "teken_state_init") {
+ print "\t\tteken_subr_regular_character(t, c);";
+ } else {
+ print "\t\tteken_printf(\"Unsupported sequence in " l_prefix_name[p] ": %u\\n\", (unsigned int)c);";
+ }
+ print "\t\tbreak;";
+
+ print "\t}";
+
+ if (l_prefix_name[p] != "teken_state_init") {
+ print "";
+ print "\tteken_state_switch(t, teken_state_init);";
+ }
+ print "}";
+}
+
+}
diff --git a/sys/dev/syscons/teken/sequences b/sys/dev/syscons/teken/sequences
new file mode 100644
index 000000000000..59d324573fdf
--- /dev/null
+++ b/sys/dev/syscons/teken/sequences
@@ -0,0 +1,109 @@
+#-
+# Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+# File format is as follows:
+# Abbr Abbreviation of sequence name
+# Name Sequence name (will be converted to C function name)
+# Sequence Bytes that form the sequence
+# Arguments Standard value of arguments passed to this sequence
+# - `n' non-zero number (0 gets converted to 1)
+# - `r' regular numeric argument
+# - `v' means a variable number of arguments
+
+# Abbr Name Sequence Arguments
+CBT Cursor Backward Tabulation ^[ [ Z n
+CHT Cursor Forward Tabulation ^[ [ I n
+CNL Cursor Next Line ^[ [ E n
+CPL Cursor Previous Line ^[ [ F n
+CPR Cursor Position Report ^[ [ n r
+CUB Cursor Backward ^[ [ D n
+CUD Cursor Down ^[ [ B n
+CUD Cursor Down ^[ [ e n
+CUF Cursor Forward ^[ [ C n
+CUF Cursor Forward ^[ [ a n
+CUP Cursor Position ^[ [ H n n
+CUP Cursor Position ^[ [ f n n
+CUU Cursor Up ^[ [ A n
+DA1 Primary Device Attributes ^[ [ c r
+DA2 Secondary Device Attributes ^[ [ > c r
+DC Delete character ^[ [ P n
+DCS Device Control String ^[ P
+DECALN Alignment test ^[ # 8
+DECDHL Double Height Double Width Line Top ^[ # 3
+DECDHL Double Height Double Width Line Bottom ^[ # 4
+DECDWL Single Height Double Width Line ^[ # 6
+DECKPAM Keypad application mode ^[ =
+DECKPNM Keypad numeric mode ^[ >
+DECRC Restore cursor ^[ 8
+DECRC Restore cursor ^[ [ u
+DECRM Reset DEC mode ^[ [ ? l r
+DECSC Save cursor ^[ 7
+DECSC Save cursor ^[ [ s
+DECSM Set DEC mode ^[ [ ? h r
+DECSTBM Set top and bottom margins ^[ [ r r r
+DECSWL Single Height Single Width Line ^[ # 5
+DL Delete line ^[ [ M n
+DSR Device Status Report ^[ [ ? n r
+ECH Erase character ^[ [ X n
+ED Erase display ^[ [ J r
+EL Erase line ^[ [ K r
+G0SCS0 G0 SCS Special Graphics ^[ ( 0
+G0SCS1 G0 SCS US ASCII ^[ ( 1
+G0SCS2 G0 SCS Special Graphics ^[ ( 2
+G0SCSA G0 SCS UK National ^[ ( A
+G0SCSB G0 SCS US ASCII ^[ ( B
+G1SCS0 G1 SCS Special Graphics ^[ ) 0
+G1SCS1 G1 SCS US ASCII ^[ ) 1
+G1SCS2 G1 SCS Special Graphics ^[ ) 2
+G1SCSA G1 SCS UK National ^[ ) A
+G1SCSB G1 SCS US ASCII ^[ ) B
+HPA Horizontal Position Absolute ^[ [ G n
+HPA Horizontal Position Absolute ^[ [ ` n
+HTS Horizontal Tab Set ^[ H
+ICH Insert character ^[ [ @ n
+IL Insert line ^[ [ L n
+IND Index ^[ D
+NEL Next line ^[ E
+RI Reverse index ^[ M
+RIS Reset to Initial State ^[ c
+RM Reset Mode ^[ [ l r
+SD Pan Up ^[ [ T n
+SGR Set Graphic Rendition ^[ [ m v
+SM Set Mode ^[ [ h r
+ST String Terminator ^[ \\
+SU Pan Down ^[ [ S n
+TBC Tab Clear ^[ [ g r
+VPA Vertical Position Absolute ^[ [ d n
+
+# Cons25 compatibility sequences
+C25ADBG Cons25 set adapter background ^[ [ = G r
+C25ADFG Cons25 set adapter foreground ^[ [ = F r
+C25CURS Cons25 set cursor type ^[ [ = S r
+C25VTSW Cons25 switch virtual terminal ^[ [ z r
+
+# VT52 compatibility
+#DECID VT52 DECID ^[ Z
diff --git a/sys/dev/syscons/teken/teken.c b/sys/dev/syscons/teken/teken.c
new file mode 100644
index 000000000000..30845c49a63b
--- /dev/null
+++ b/sys/dev/syscons/teken/teken.c
@@ -0,0 +1,430 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/systm.h>
+#define teken_assert(x) MPASS(x)
+#define teken_printf(x,...)
+#else /* !(__FreeBSD__ && _KERNEL) */
+#include <sys/types.h>
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#define teken_assert(x) assert(x)
+#define teken_printf(x,...) do { \
+ if (df != NULL) \
+ fprintf(df, x, ## __VA_ARGS__); \
+} while (0)
+/* debug messages */
+static FILE *df;
+#endif /* __FreeBSD__ && _KERNEL */
+
+#include "teken.h"
+
+#ifdef TEKEN_UTF8
+#include "teken_wcwidth.h"
+#else /* !TEKEN_UTF8 */
+#ifdef TEKEN_XTERM
+#define teken_wcwidth(c) ((c <= 0x1B) ? -1 : 1)
+#else /* !TEKEN_XTERM */
+#define teken_wcwidth(c) (1)
+#endif /* TEKEN_XTERM */
+#endif /* TEKEN_UTF8 */
+
+#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
+#include "teken_scs.h"
+#else /* !(TEKEN_XTERM && TEKEN_UTF8) */
+#define teken_scs_process(t, c) (c)
+#define teken_scs_restore(t)
+#define teken_scs_save(t)
+#define teken_scs_set(t, g, ts)
+#define teken_scs_switch(t, g)
+#endif /* TEKEN_XTERM && TEKEN_UTF8 */
+
+/* Private flags for teken_format_t. */
+#define TF_REVERSE 0x08
+
+/* Private flags for t_stateflags. */
+#define TS_FIRSTDIGIT 0x01 /* First numeric digit in escape sequence. */
+#define TS_INSERT 0x02 /* Insert mode. */
+#define TS_AUTOWRAP 0x04 /* Autowrap. */
+#define TS_ORIGIN 0x08 /* Origin mode. */
+#ifdef TEKEN_XTERM
+#define TS_WRAPPED 0x10 /* Next character should be printed on col 0. */
+#else /* !TEKEN_XTERM */
+#define TS_WRAPPED 0x00 /* Simple line wrapping. */
+#endif /* TEKEN_XTERM */
+
+/* Character that blanks a cell. */
+#define BLANK ' '
+
+static teken_state_t teken_state_init;
+
+/*
+ * Wrappers for hooks.
+ */
+
+static inline void
+teken_funcs_bell(teken_t *t)
+{
+
+ t->t_funcs->tf_bell(t->t_softc);
+}
+
+static inline void
+teken_funcs_cursor(teken_t *t)
+{
+
+ teken_assert(t->t_cursor.tp_row < t->t_winsize.tp_row);
+ teken_assert(t->t_cursor.tp_col < t->t_winsize.tp_col);
+
+ t->t_funcs->tf_cursor(t->t_softc, &t->t_cursor);
+}
+
+static inline void
+teken_funcs_putchar(teken_t *t, const teken_pos_t *p, teken_char_t c,
+ const teken_attr_t *a)
+{
+ teken_attr_t ta;
+
+ teken_assert(p->tp_row < t->t_winsize.tp_row);
+ teken_assert(p->tp_col < t->t_winsize.tp_col);
+
+ /* Apply inversion. */
+ if (a->ta_format & TF_REVERSE) {
+ ta.ta_format = a->ta_format;
+ ta.ta_fgcolor = a->ta_bgcolor;
+ ta.ta_bgcolor = a->ta_fgcolor;
+ a = &ta;
+ }
+
+ t->t_funcs->tf_putchar(t->t_softc, p, c, a);
+}
+
+static inline void
+teken_funcs_fill(teken_t *t, const teken_rect_t *r,
+ const teken_char_t c, const teken_attr_t *a)
+{
+ teken_attr_t ta;
+
+ teken_assert(r->tr_end.tp_row > r->tr_begin.tp_row);
+ teken_assert(r->tr_end.tp_row <= t->t_winsize.tp_row);
+ teken_assert(r->tr_end.tp_col > r->tr_begin.tp_col);
+ teken_assert(r->tr_end.tp_col <= t->t_winsize.tp_col);
+
+ /* Apply inversion. */
+ if (a->ta_format & TF_REVERSE) {
+ ta.ta_format = a->ta_format;
+ ta.ta_fgcolor = a->ta_bgcolor;
+ ta.ta_bgcolor = a->ta_fgcolor;
+ a = &ta;
+ }
+
+ t->t_funcs->tf_fill(t->t_softc, r, c, a);
+}
+
+static inline void
+teken_funcs_copy(teken_t *t, const teken_rect_t *r, const teken_pos_t *p)
+{
+
+ teken_assert(r->tr_end.tp_row > r->tr_begin.tp_row);
+ teken_assert(r->tr_end.tp_row <= t->t_winsize.tp_row);
+ teken_assert(r->tr_end.tp_col > r->tr_begin.tp_col);
+ teken_assert(r->tr_end.tp_col <= t->t_winsize.tp_col);
+ teken_assert(p->tp_row + (r->tr_end.tp_row - r->tr_begin.tp_row) <= t->t_winsize.tp_row);
+ teken_assert(p->tp_col + (r->tr_end.tp_col - r->tr_begin.tp_col) <= t->t_winsize.tp_col);
+
+ t->t_funcs->tf_copy(t->t_softc, r, p);
+}
+
+static inline void
+teken_funcs_param(teken_t *t, int cmd, int value)
+{
+
+ t->t_funcs->tf_param(t->t_softc, cmd, value);
+}
+
+static inline void
+teken_funcs_respond(teken_t *t, const void *buf, size_t len)
+{
+
+ t->t_funcs->tf_respond(t->t_softc, buf, len);
+}
+
+#include "teken_subr.h"
+#include "teken_subr_compat.h"
+
+/*
+ * Programming interface.
+ */
+
+void
+teken_init(teken_t *t, const teken_funcs_t *tf, void *softc)
+{
+ teken_pos_t tp = { .tp_row = 24, .tp_col = 80 };
+
+#if !(defined(__FreeBSD__) && defined(_KERNEL))
+ df = fopen("teken.log", "w");
+ if (df != NULL)
+ setvbuf(df, NULL, _IOLBF, BUFSIZ);
+#endif /* !(__FreeBSD__ && _KERNEL) */
+
+ t->t_funcs = tf;
+ t->t_softc = softc;
+
+ t->t_nextstate = teken_state_init;
+
+ t->t_defattr.ta_format = 0;
+ t->t_defattr.ta_fgcolor = TC_WHITE;
+ t->t_defattr.ta_bgcolor = TC_BLACK;
+ teken_subr_do_reset(t);
+
+#ifdef TEKEN_UTF8
+ t->t_utf8_left = 0;
+#endif /* TEKEN_UTF8 */
+
+ teken_set_winsize(t, &tp);
+}
+
+static void
+teken_input_char(teken_t *t, teken_char_t c)
+{
+
+ switch (c) {
+ case '\0':
+ break;
+ case '\a':
+ teken_subr_bell(t);
+ break;
+ case '\b':
+ teken_subr_backspace(t);
+ break;
+ case '\n':
+ case '\x0B':
+ teken_subr_newline(t);
+ break;
+ case '\x0C':
+ teken_subr_newpage(t);
+ break;
+#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
+ case '\x0E':
+ teken_scs_switch(t, 1);
+ break;
+ case '\x0F':
+ teken_scs_switch(t, 0);
+ break;
+#endif /* TEKEN_XTERM && TEKEN_UTF8 */
+ case '\r':
+ teken_subr_carriage_return(t);
+ break;
+ case '\t':
+ teken_subr_horizontal_tab(t);
+ break;
+ default:
+ t->t_nextstate(t, c);
+ break;
+ }
+
+ /* Post-processing assertions. */
+ teken_assert(t->t_cursor.tp_row >= t->t_originreg.ts_begin);
+ teken_assert(t->t_cursor.tp_row < t->t_originreg.ts_end);
+ teken_assert(t->t_cursor.tp_row < t->t_winsize.tp_row);
+ teken_assert(t->t_cursor.tp_col < t->t_winsize.tp_col);
+ teken_assert(t->t_saved_cursor.tp_row < t->t_winsize.tp_row);
+ teken_assert(t->t_saved_cursor.tp_col < t->t_winsize.tp_col);
+ teken_assert(t->t_scrollreg.ts_end <= t->t_winsize.tp_row);
+ teken_assert(t->t_scrollreg.ts_begin < t->t_scrollreg.ts_end);
+ /* Origin region has to be window size or the same as scrollreg. */
+ teken_assert((t->t_originreg.ts_begin == t->t_scrollreg.ts_begin &&
+ t->t_originreg.ts_end == t->t_scrollreg.ts_end) ||
+ (t->t_originreg.ts_begin == 0 &&
+ t->t_originreg.ts_end == t->t_winsize.tp_row));
+}
+
+static void
+teken_input_byte(teken_t *t, unsigned char c)
+{
+
+#ifdef TEKEN_UTF8
+ /*
+ * UTF-8 handling.
+ */
+ if ((c & 0x80) == 0x00) {
+ /* One-byte sequence. */
+ t->t_utf8_left = 0;
+ teken_input_char(t, c);
+ } else if ((c & 0xe0) == 0xc0) {
+ /* Two-byte sequence. */
+ t->t_utf8_left = 1;
+ t->t_utf8_partial = c & 0x1f;
+ } else if ((c & 0xf0) == 0xe0) {
+ /* Three-byte sequence. */
+ t->t_utf8_left = 2;
+ t->t_utf8_partial = c & 0x0f;
+ } else if ((c & 0xf8) == 0xf0) {
+ /* Four-byte sequence. */
+ t->t_utf8_left = 3;
+ t->t_utf8_partial = c & 0x07;
+ } else if ((c & 0xc0) == 0x80) {
+ if (t->t_utf8_left == 0)
+ return;
+ t->t_utf8_left--;
+ t->t_utf8_partial = (t->t_utf8_partial << 6) | (c & 0x3f);
+ if (t->t_utf8_left == 0) {
+ teken_printf("Got UTF-8 char %u\n", t->t_utf8_partial);
+ teken_input_char(t, t->t_utf8_partial);
+ }
+ }
+#else /* !TEKEN_UTF8 */
+ teken_input_char(t, c);
+#endif /* TEKEN_UTF8 */
+}
+
+void
+teken_input(teken_t *t, const void *buf, size_t len)
+{
+ const char *c = buf;
+
+ while (len-- > 0)
+ teken_input_byte(t, *c++);
+}
+
+void
+teken_set_cursor(teken_t *t, const teken_pos_t *p)
+{
+
+ /* XXX: bounds checking with originreg! */
+ teken_assert(p->tp_row < t->t_winsize.tp_row);
+ teken_assert(p->tp_col < t->t_winsize.tp_col);
+
+ t->t_cursor = *p;
+}
+
+const teken_attr_t *
+teken_get_curattr(teken_t *t)
+{
+
+ return (&t->t_curattr);
+}
+
+void
+teken_set_curattr(teken_t *t, const teken_attr_t *a)
+{
+
+ t->t_curattr = *a;
+}
+
+const teken_attr_t *
+teken_get_defattr(teken_t *t)
+{
+
+ return (&t->t_defattr);
+}
+
+void
+teken_set_defattr(teken_t *t, const teken_attr_t *a)
+{
+
+ t->t_curattr = t->t_saved_curattr = t->t_defattr = *a;
+}
+
+void
+teken_set_winsize(teken_t *t, const teken_pos_t *p)
+{
+
+ t->t_winsize = *p;
+ /* XXX: bounds checking with cursor/etc! */
+ t->t_scrollreg.ts_begin = 0;
+ t->t_scrollreg.ts_end = t->t_winsize.tp_row;
+ t->t_originreg = t->t_scrollreg;
+}
+
+/*
+ * State machine.
+ */
+
+static void
+teken_state_switch(teken_t *t, teken_state_t *s)
+{
+
+ t->t_nextstate = s;
+ t->t_curnum = 0;
+ t->t_stateflags |= TS_FIRSTDIGIT;
+}
+
+static int
+teken_state_numbers(teken_t *t, teken_char_t c)
+{
+
+ teken_assert(t->t_curnum < T_NUMSIZE);
+
+ if (c >= '0' && c <= '9') {
+ /*
+ * Don't do math with the default value of 1 when a
+ * custom number is inserted.
+ */
+ if (t->t_stateflags & TS_FIRSTDIGIT) {
+ t->t_stateflags &= ~TS_FIRSTDIGIT;
+ t->t_nums[t->t_curnum] = 0;
+ } else {
+ t->t_nums[t->t_curnum] *= 10;
+ }
+
+ t->t_nums[t->t_curnum] += c - '0';
+ return (1);
+ } else if (c == ';') {
+ if (t->t_stateflags & TS_FIRSTDIGIT)
+ t->t_nums[t->t_curnum] = 0;
+
+ /* Only allow a limited set of arguments. */
+ if (++t->t_curnum == T_NUMSIZE) {
+ teken_state_switch(t, teken_state_init);
+ return (1);
+ }
+
+ t->t_stateflags |= TS_FIRSTDIGIT;
+ return (1);
+ } else {
+ if (t->t_stateflags & TS_FIRSTDIGIT && t->t_curnum > 0) {
+ /* Finish off the last empty argument. */
+ t->t_nums[t->t_curnum] = 0;
+ t->t_curnum++;
+ } else if ((t->t_stateflags & TS_FIRSTDIGIT) == 0) {
+ /* Also count the last argument. */
+ t->t_curnum++;
+ }
+ }
+
+ return (0);
+}
+
+#include "teken_state.h"
diff --git a/sys/dev/syscons/teken/teken.h b/sys/dev/syscons/teken/teken.h
new file mode 100644
index 000000000000..620dfd57e670
--- /dev/null
+++ b/sys/dev/syscons/teken/teken.h
@@ -0,0 +1,181 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _TEKEN_H_
+#define _TEKEN_H_
+
+/*
+ * libteken: terminal emulation library.
+ *
+ * This library converts an UTF-8 stream of bytes to terminal drawing
+ * commands.
+ *
+ * Configuration switches:
+ * - TEKEN_UTF8: Enable/disable UTF-8 handling.
+ * - TEKEN_XTERM: Enable xterm-style emulation, instead of cons25.
+ */
+
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include "opt_teken.h"
+#endif /* __FreeBSD__ && _KERNEL */
+
+#ifdef TEKEN_UTF8
+typedef uint32_t teken_char_t;
+#else /* !TEKEN_UTF8 */
+typedef unsigned char teken_char_t;
+#endif /* TEKEN_UTF8 */
+typedef unsigned short teken_unit_t;
+typedef unsigned char teken_format_t;
+#define TF_BOLD 0x01
+#define TF_UNDERLINE 0x02
+#define TF_BLINK 0x04
+typedef unsigned char teken_color_t;
+#define TC_BLACK 0
+#define TC_RED 1
+#define TC_GREEN 2
+#define TC_BROWN 3
+#define TC_BLUE 4
+#define TC_MAGENTA 5
+#define TC_CYAN 6
+#define TC_WHITE 7
+#define TC_NCOLORS 8
+
+typedef struct {
+ teken_unit_t tp_row;
+ teken_unit_t tp_col;
+} teken_pos_t;
+typedef struct {
+ teken_pos_t tr_begin;
+ teken_pos_t tr_end;
+} teken_rect_t;
+typedef struct {
+ teken_format_t ta_format;
+ teken_color_t ta_fgcolor;
+ teken_color_t ta_bgcolor;
+} teken_attr_t;
+typedef struct {
+ teken_unit_t ts_begin;
+ teken_unit_t ts_end;
+} teken_span_t;
+
+typedef struct __teken teken_t;
+
+typedef void teken_state_t(teken_t *, teken_char_t);
+
+/*
+ * Drawing routines supplied by the user.
+ */
+
+typedef void tf_bell_t(void *);
+typedef void tf_cursor_t(void *, const teken_pos_t *);
+typedef void tf_putchar_t(void *, const teken_pos_t *, teken_char_t,
+ const teken_attr_t *);
+typedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t,
+ const teken_attr_t *);
+typedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *);
+typedef void tf_param_t(void *, int, int);
+#define TP_SHOWCURSOR 0
+#define TP_CURSORKEYS 1
+#define TP_KEYPADAPP 2
+#define TP_AUTOREPEAT 3
+#define TP_SWITCHVT 4
+#define TP_132COLS 5
+typedef void tf_respond_t(void *, const void *, size_t);
+
+typedef struct {
+ tf_bell_t *tf_bell;
+ tf_cursor_t *tf_cursor;
+ tf_putchar_t *tf_putchar;
+ tf_fill_t *tf_fill;
+ tf_copy_t *tf_copy;
+ tf_param_t *tf_param;
+ tf_respond_t *tf_respond;
+} teken_funcs_t;
+
+#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
+typedef teken_char_t teken_scs_t(teken_char_t);
+#endif /* TEKEN_XTERM && TEKEN_UTF8 */
+
+/*
+ * Terminal state.
+ */
+
+struct __teken {
+ const teken_funcs_t *t_funcs;
+ void *t_softc;
+
+ teken_state_t *t_nextstate;
+ unsigned int t_stateflags;
+
+#define T_NUMSIZE 8
+ unsigned int t_nums[T_NUMSIZE];
+ unsigned int t_curnum;
+
+ teken_pos_t t_cursor;
+ teken_attr_t t_curattr;
+ teken_pos_t t_saved_cursor;
+ teken_attr_t t_saved_curattr;
+
+ teken_attr_t t_defattr;
+ teken_pos_t t_winsize;
+
+ /* For DECSTBM. */
+ teken_span_t t_scrollreg;
+ /* For DECOM. */
+ teken_span_t t_originreg;
+
+#define T_NUMCOL 160
+ unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)];
+
+#ifdef TEKEN_UTF8
+ unsigned int t_utf8_left;
+ teken_char_t t_utf8_partial;
+#endif /* TEKEN_UTF8 */
+
+#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
+ unsigned int t_curscs;
+ teken_scs_t *t_saved_curscs;
+ teken_scs_t *t_scs[2];
+#endif /* TEKEN_XTERM && TEKEN_UTF8 */
+};
+
+/* Initialize teken structure. */
+void teken_init(teken_t *, const teken_funcs_t *, void *);
+
+/* Deliver character input. */
+void teken_input(teken_t *, const void *, size_t);
+
+/* Get/set teken attributes. */
+const teken_attr_t *teken_get_curattr(teken_t *);
+const teken_attr_t *teken_get_defattr(teken_t *);
+void teken_set_cursor(teken_t *, const teken_pos_t *);
+void teken_set_curattr(teken_t *, const teken_attr_t *);
+void teken_set_defattr(teken_t *, const teken_attr_t *);
+void teken_set_winsize(teken_t *, const teken_pos_t *);
+
+#endif /* !_TEKEN_H_ */
diff --git a/sys/dev/syscons/teken/teken_demo.c b/sys/dev/syscons/teken/teken_demo.c
new file mode 100644
index 000000000000..bacfd68b1e0c
--- /dev/null
+++ b/sys/dev/syscons/teken/teken_demo.c
@@ -0,0 +1,367 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/ioctl.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ncurses.h>
+#if defined(__FreeBSD__)
+#include <libutil.h>
+#elif defined(__linux__)
+#include <pty.h>
+#else
+#include <util.h>
+#endif
+
+#include "teken.h"
+
+static tf_bell_t test_bell;
+static tf_cursor_t test_cursor;
+static tf_putchar_t test_putchar;
+static tf_fill_t test_fill;
+static tf_copy_t test_copy;
+static tf_param_t test_param;
+static tf_respond_t test_respond;
+
+static teken_funcs_t tf = {
+ .tf_bell = test_bell,
+ .tf_cursor = test_cursor,
+ .tf_putchar = test_putchar,
+ .tf_fill = test_fill,
+ .tf_copy = test_copy,
+ .tf_param = test_param,
+ .tf_respond = test_respond,
+};
+
+struct pixel {
+ teken_char_t c;
+ teken_attr_t a;
+};
+
+#define NCOLS 80
+#ifdef TEKEN_XTERM
+#define NROWS 24
+#else /* !TEKEN_XTERM */
+#define NROWS 25
+#endif /* TEKEN_XTERM */
+struct pixel buffer[NCOLS][NROWS];
+
+static int ptfd;
+
+static void
+printchar(const teken_pos_t *p)
+{
+ int y, x, attr = 0;
+ struct pixel *px;
+ char str[5] = { 0 };
+
+ assert(p->tp_row < NROWS);
+ assert(p->tp_col < NCOLS);
+
+ getyx(stdscr, y, x);
+
+ px = &buffer[p->tp_col][p->tp_row];
+
+ /* Convert Unicode to UTF-8. */
+#ifdef TEKEN_UTF8
+ if (px->c < 0x80) {
+ str[0] = px->c;
+ } else if (px->c < 0x800) {
+ str[0] = 0xc0 | (px->c >> 6);
+ str[1] = 0x80 | (px->c & 0x3f);
+ } else if (px->c < 0x10000) {
+ str[0] = 0xe0 | (px->c >> 12);
+ str[1] = 0x80 | ((px->c >> 6) & 0x3f);
+ str[2] = 0x80 | (px->c & 0x3f);
+ } else {
+ str[0] = 0xf0 | (px->c >> 18);
+ str[1] = 0x80 | ((px->c >> 12) & 0x3f);
+ str[2] = 0x80 | ((px->c >> 6) & 0x3f);
+ str[3] = 0x80 | (px->c & 0x3f);
+ }
+#else /* !TEKEN_UTF8 */
+ str[0] = px->c;
+#endif /* TEKEN_UTF8 */
+
+ if (px->a.ta_format & TF_BOLD)
+ attr |= A_BOLD;
+ if (px->a.ta_format & TF_UNDERLINE)
+ attr |= A_UNDERLINE;
+ if (px->a.ta_format & TF_BLINK)
+ attr |= A_BLINK;
+
+ bkgdset(attr | COLOR_PAIR(px->a.ta_fgcolor + 8 * px->a.ta_bgcolor));
+ mvaddstr(p->tp_row, p->tp_col, str);
+
+ move(y, x);
+}
+
+static void
+test_bell(void *s __unused)
+{
+
+ beep();
+}
+
+static void
+test_cursor(void *s __unused, const teken_pos_t *p)
+{
+
+ move(p->tp_row, p->tp_col);
+}
+
+static void
+test_putchar(void *s __unused, const teken_pos_t *p, teken_char_t c,
+ const teken_attr_t *a)
+{
+
+ buffer[p->tp_col][p->tp_row].c = c;
+ buffer[p->tp_col][p->tp_row].a = *a;
+ printchar(p);
+}
+
+static void
+test_fill(void *s, const teken_rect_t *r, teken_char_t c,
+ const teken_attr_t *a)
+{
+ teken_pos_t p;
+
+ /* Braindead implementation of fill() - just call putchar(). */
+ for (p.tp_row = r->tr_begin.tp_row; p.tp_row < r->tr_end.tp_row; p.tp_row++)
+ for (p.tp_col = r->tr_begin.tp_col; p.tp_col < r->tr_end.tp_col; p.tp_col++)
+ test_putchar(s, &p, c, a);
+}
+
+static void
+test_copy(void *s __unused, const teken_rect_t *r, const teken_pos_t *p)
+{
+ int nrow, ncol, x, y; /* Has to be signed - >= 0 comparison */
+ teken_pos_t d;
+
+ /*
+ * Copying is a little tricky. We must make sure we do it in
+ * correct order, to make sure we don't overwrite our own data.
+ */
+
+ nrow = r->tr_end.tp_row - r->tr_begin.tp_row;
+ ncol = r->tr_end.tp_col - r->tr_begin.tp_col;
+
+ if (p->tp_row < r->tr_begin.tp_row) {
+ /* Copy from top to bottom. */
+ if (p->tp_col < r->tr_begin.tp_col) {
+ /* Copy from left to right. */
+ for (y = 0; y < nrow; y++) {
+ d.tp_row = p->tp_row + y;
+ for (x = 0; x < ncol; x++) {
+ d.tp_col = p->tp_col + x;
+ buffer[d.tp_col][d.tp_row] =
+ buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y];
+ printchar(&d);
+ }
+ }
+ } else {
+ /* Copy from right to left. */
+ for (y = 0; y < nrow; y++) {
+ d.tp_row = p->tp_row + y;
+ for (x = ncol - 1; x >= 0; x--) {
+ d.tp_col = p->tp_col + x;
+ buffer[d.tp_col][d.tp_row] =
+ buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y];
+ printchar(&d);
+ }
+ }
+ }
+ } else {
+ /* Copy from bottom to top. */
+ if (p->tp_col < r->tr_begin.tp_col) {
+ /* Copy from left to right. */
+ for (y = nrow - 1; y >= 0; y--) {
+ d.tp_row = p->tp_row + y;
+ for (x = 0; x < ncol; x++) {
+ d.tp_col = p->tp_col + x;
+ buffer[d.tp_col][d.tp_row] =
+ buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y];
+ printchar(&d);
+ }
+ }
+ } else {
+ /* Copy from right to left. */
+ for (y = nrow - 1; y >= 0; y--) {
+ d.tp_row = p->tp_row + y;
+ for (x = ncol - 1; x >= 0; x--) {
+ d.tp_col = p->tp_col + x;
+ buffer[d.tp_col][d.tp_row] =
+ buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y];
+ printchar(&d);
+ }
+ }
+ }
+ }
+}
+
+static void
+test_param(void *s __unused, int cmd, int value)
+{
+
+ switch (cmd) {
+ case TP_SHOWCURSOR:
+ curs_set(value);
+ break;
+ case TP_KEYPADAPP:
+ keypad(stdscr, value ? TRUE : FALSE);
+ break;
+ }
+}
+
+static void
+test_respond(void *s __unused, const void *buf, size_t len)
+{
+
+ write(ptfd, buf, len);
+}
+
+static void
+redraw_border(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < NROWS; i++)
+ mvaddch(i, NCOLS, '|');
+ for (i = 0; i < NCOLS; i++)
+ mvaddch(NROWS, i, '-');
+
+ mvaddch(NROWS, NCOLS, '+');
+}
+
+static void
+redraw_all(void)
+{
+ teken_pos_t tp;
+
+ for (tp.tp_row = 0; tp.tp_row < NROWS; tp.tp_row++)
+ for (tp.tp_col = 0; tp.tp_col < NCOLS; tp.tp_col++)
+ printchar(&tp);
+
+ redraw_border();
+}
+
+int
+main(int argc __unused, char *argv[] __unused)
+{
+ struct winsize ws;
+ teken_t t;
+ teken_pos_t tp;
+ fd_set rfds;
+ char b[256];
+ ssize_t bl;
+ const int ccolors[8] = {
+ COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
+ COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE
+ };
+ int i, j;
+
+#ifdef TEKEN_UTF8
+ setlocale(LC_CTYPE, "UTF-8");
+#endif /* TEKEN_UTF8 */
+
+ tp.tp_row = ws.ws_row = NROWS;
+ tp.tp_col = ws.ws_col = NCOLS;
+
+ switch (forkpty(&ptfd, NULL, NULL, &ws)) {
+ case -1:
+ perror("forkpty");
+ exit(1);
+ case 0:
+#ifdef TEKEN_XTERM
+ setenv("TERM", "xterm", 1);
+#else /* !TEKEN_XTERM */
+ setenv("TERM", "cons25", 1);
+#endif /* TEKEN_XTERM */
+#ifdef TEKEN_UTF8
+ setenv("LC_CTYPE", "UTF-8", 0);
+#endif /* TEKEN_UTF8 */
+ execlp("zsh", "-zsh", NULL);
+ execlp("bash", "-bash", NULL);
+ execlp("sh", "-sh", NULL);
+ _exit(1);
+ }
+
+ teken_init(&t, &tf, NULL);
+ teken_set_winsize(&t, &tp);
+
+ initscr();
+ raw();
+ start_color();
+ for (i = 0; i < 8; i++)
+ for (j = 0; j < 8; j++)
+ init_pair(i + 8 * j, ccolors[i], ccolors[j]);
+
+ redraw_border();
+
+ FD_ZERO(&rfds);
+
+ for (;;) {
+ FD_SET(STDIN_FILENO, &rfds);
+ FD_SET(ptfd, &rfds);
+
+ if (select(ptfd + 1, &rfds, NULL, NULL, NULL) < 0) {
+ if (errno == EINTR) {
+ redraw_all();
+ refresh();
+ continue;
+ }
+ break;
+ }
+
+ if (FD_ISSET(STDIN_FILENO, &rfds)) {
+ bl = read(STDIN_FILENO, b, sizeof b);
+ if (bl <= 0)
+ break;
+ write(ptfd, b, bl);
+ }
+
+ if (FD_ISSET(ptfd, &rfds)) {
+ bl = read(ptfd, b, sizeof b);
+ if (bl <= 0)
+ break;
+ teken_input(&t, b, bl);
+ refresh();
+ }
+ }
+
+ endwin();
+
+ return (0);
+}
diff --git a/sys/dev/syscons/teken/teken_scs.h b/sys/dev/syscons/teken/teken_scs.h
new file mode 100644
index 000000000000..baeb296539d4
--- /dev/null
+++ b/sys/dev/syscons/teken/teken_scs.h
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+static void
+teken_scs_set(teken_t *t, unsigned int g, teken_scs_t *ts)
+{
+
+ t->t_scs[g] = ts;
+}
+
+static void
+teken_scs_switch(teken_t *t, unsigned int g)
+{
+
+ t->t_curscs = g;
+}
+
+static void
+teken_scs_restore(teken_t *t)
+{
+
+ t->t_scs[t->t_curscs] = t->t_saved_curscs;
+}
+
+static void
+teken_scs_save(teken_t *t)
+{
+
+ t->t_saved_curscs = t->t_scs[t->t_curscs];
+}
+
+static teken_char_t
+teken_scs_process(teken_t *t, teken_char_t c)
+{
+
+ return (t->t_scs[t->t_curscs](c));
+}
+
+/* Unicode points for VT100 box drawing. */
+static const uint16_t teken_boxdrawing[31] = {
+ 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1,
+ 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba,
+ 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c,
+ 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7
+};
+
+static teken_char_t
+teken_scs_special_graphics(teken_char_t c)
+{
+
+ /* Box drawing. */
+ if (c >= '`' && c <= '~')
+ return (teken_boxdrawing[c - '`']);
+ return (c);
+}
+
+static teken_char_t
+teken_scs_uk_national(teken_char_t c)
+{
+
+ /* Pound sign. */
+ if (c == '#')
+ return (0xa3);
+ return (c);
+}
+
+static teken_char_t
+teken_scs_us_ascii(teken_char_t c)
+{
+
+ /* No processing. */
+ return (c);
+}
diff --git a/sys/dev/syscons/teken/teken_stress.c b/sys/dev/syscons/teken/teken_stress.c
new file mode 100644
index 000000000000..1b716473be29
--- /dev/null
+++ b/sys/dev/syscons/teken/teken_stress.c
@@ -0,0 +1,123 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "teken.h"
+
+static tf_bell_t stress_bell;
+static tf_cursor_t stress_cursor;
+static tf_putchar_t stress_putchar;
+static tf_fill_t stress_fill;
+static tf_copy_t stress_copy;
+static tf_param_t stress_param;
+static tf_respond_t stress_respond;
+
+static teken_funcs_t tf = {
+ .tf_bell = stress_bell,
+ .tf_cursor = stress_cursor,
+ .tf_putchar = stress_putchar,
+ .tf_fill = stress_fill,
+ .tf_copy = stress_copy,
+ .tf_param = stress_param,
+ .tf_respond = stress_respond,
+};
+
+static void
+stress_bell(void *s __unused)
+{
+}
+
+static void
+stress_cursor(void *s __unused, const teken_pos_t *p __unused)
+{
+}
+
+static void
+stress_putchar(void *s __unused, const teken_pos_t *p __unused,
+ teken_char_t c __unused, const teken_attr_t *a __unused)
+{
+}
+
+static void
+stress_fill(void *s __unused, const teken_rect_t *r __unused,
+ teken_char_t c __unused, const teken_attr_t *a __unused)
+{
+}
+
+static void
+stress_copy(void *s __unused, const teken_rect_t *r __unused,
+ const teken_pos_t *p __unused)
+{
+}
+
+static void
+stress_param(void *s __unused, int cmd __unused, int value __unused)
+{
+}
+
+static void
+stress_respond(void *s __unused, const void *buf __unused, size_t len __unused)
+{
+}
+
+int
+main(int argc __unused, char *argv[] __unused)
+{
+ teken_t t;
+ int rnd;
+ unsigned int iteration = 0;
+ char buf[2048];
+
+ rnd = open("/dev/urandom", O_RDONLY);
+ if (rnd < 0) {
+ perror("/dev/urandom");
+ exit(1);
+ }
+
+ teken_init(&t, &tf, NULL);
+
+ for (;;) {
+ if (read(rnd, buf, sizeof buf) != sizeof buf) {
+ perror("read");
+ exit(1);
+ }
+
+ teken_input(&t, buf, sizeof buf);
+
+ iteration++;
+ if ((iteration % 10000) == 0)
+ printf("Processed %u frames\n", iteration);
+ }
+}
diff --git a/sys/dev/syscons/teken/teken_subr.h b/sys/dev/syscons/teken/teken_subr.h
new file mode 100644
index 000000000000..21982e26d592
--- /dev/null
+++ b/sys/dev/syscons/teken/teken_subr.h
@@ -0,0 +1,1209 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+static void teken_subr_cursor_up(teken_t *, unsigned int);
+static void teken_subr_erase_line(teken_t *, unsigned int);
+static void teken_subr_regular_character(teken_t *, teken_char_t);
+static void teken_subr_reset_to_initial_state(teken_t *);
+static void teken_subr_save_cursor(teken_t *);
+
+static inline int
+teken_tab_isset(teken_t *t, unsigned int col)
+{
+ unsigned int b, o;
+
+ if (col >= T_NUMCOL)
+ return ((col % 8) == 0);
+
+ b = col / (sizeof(unsigned int) * 8);
+ o = col % (sizeof(unsigned int) * 8);
+
+ return (t->t_tabstops[b] & (1 << o));
+}
+
+static inline void
+teken_tab_clear(teken_t *t, unsigned int col)
+{
+ unsigned int b, o;
+
+ if (col >= T_NUMCOL)
+ return;
+
+ b = col / (sizeof(unsigned int) * 8);
+ o = col % (sizeof(unsigned int) * 8);
+
+ t->t_tabstops[b] &= ~(1 << o);
+}
+
+static inline void
+teken_tab_set(teken_t *t, unsigned int col)
+{
+ unsigned int b, o;
+
+ if (col >= T_NUMCOL)
+ return;
+
+ b = col / (sizeof(unsigned int) * 8);
+ o = col % (sizeof(unsigned int) * 8);
+
+ t->t_tabstops[b] |= 1 << o;
+}
+
+static void
+teken_tab_default(teken_t *t)
+{
+ unsigned int i;
+
+ memset(&t->t_tabstops, 0, T_NUMCOL / 8);
+
+ for (i = 8; i < T_NUMCOL; i += 8)
+ teken_tab_set(t, i);
+}
+
+static void
+teken_subr_do_scroll(teken_t *t, int amount)
+{
+ teken_rect_t tr;
+ teken_pos_t tp;
+
+ teken_assert(t->t_cursor.tp_row <= t->t_winsize.tp_row);
+ teken_assert(t->t_scrollreg.ts_end <= t->t_winsize.tp_row);
+ teken_assert(amount != 0);
+
+ /* Copy existing data 1 line up. */
+ if (amount > 0) {
+ /* Scroll down. */
+
+ /* Copy existing data up. */
+ if (t->t_scrollreg.ts_begin + amount < t->t_scrollreg.ts_end) {
+ tr.tr_begin.tp_row = t->t_scrollreg.ts_begin + amount;
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ tp.tp_row = t->t_scrollreg.ts_begin;
+ tp.tp_col = 0;
+ teken_funcs_copy(t, &tr, &tp);
+
+ tr.tr_begin.tp_row = t->t_scrollreg.ts_end - amount;
+ } else {
+ tr.tr_begin.tp_row = t->t_scrollreg.ts_begin;
+ }
+
+ /* Clear the last lines. */
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+ } else {
+ /* Scroll up. */
+ amount = -amount;
+
+ /* Copy existing data down. */
+ if (t->t_scrollreg.ts_begin + amount < t->t_scrollreg.ts_end) {
+ tr.tr_begin.tp_row = t->t_scrollreg.ts_begin;
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end - amount;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ tp.tp_row = t->t_scrollreg.ts_begin + amount;
+ tp.tp_col = 0;
+ teken_funcs_copy(t, &tr, &tp);
+
+ tr.tr_end.tp_row = t->t_scrollreg.ts_begin + amount;
+ } else {
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end;
+ }
+
+ /* Clear the first lines. */
+ tr.tr_begin.tp_row = t->t_scrollreg.ts_begin;
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+ }
+}
+
+static ssize_t
+teken_subr_do_cpr(teken_t *t, unsigned int cmd, char response[16])
+{
+
+ switch (cmd) {
+ case 5: /* Operating status. */
+ strcpy(response, "0n");
+ return (2);
+ case 6: { /* Cursor position. */
+ int len;
+
+ len = snprintf(response, 16, "%u;%uR",
+ (t->t_cursor.tp_row - t->t_originreg.ts_begin) + 1,
+ t->t_cursor.tp_col + 1);
+
+ if (len >= 16)
+ return (-1);
+ return (len);
+ }
+ case 15: /* Printer status. */
+ strcpy(response, "13n");
+ return (3);
+ case 25: /* UDK status. */
+ strcpy(response, "20n");
+ return (3);
+ case 26: /* Keyboard status. */
+ strcpy(response, "27;1n");
+ return (5);
+ default:
+ teken_printf("Unknown DSR\n");
+ return (-1);
+ }
+}
+
+static void
+teken_subr_alignment_test(teken_t *t)
+{
+ teken_rect_t tr;
+
+ t->t_scrollreg.ts_begin = 0;
+ t->t_scrollreg.ts_end = t->t_winsize.tp_row;
+
+ t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+
+ tr.tr_begin.tp_row = 0;
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end = t->t_winsize;
+ teken_funcs_fill(t, &tr, 'E', &t->t_defattr);
+}
+
+static void
+teken_subr_backspace(teken_t *t)
+{
+
+#ifdef TEKEN_XTERM
+ if (t->t_cursor.tp_col == 0)
+ return;
+
+ t->t_cursor.tp_col--;
+ t->t_stateflags &= ~TS_WRAPPED;
+#else /* !TEKEN_XTERM */
+ if (t->t_cursor.tp_col == 0) {
+ if (t->t_cursor.tp_row == t->t_originreg.ts_begin)
+ return;
+ t->t_cursor.tp_row--;
+ t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+ } else {
+ t->t_cursor.tp_col--;
+ }
+#endif /* TEKEN_XTERM */
+
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_bell(teken_t *t)
+{
+
+ teken_funcs_bell(t);
+}
+
+static void
+teken_subr_carriage_return(teken_t *t)
+{
+
+ t->t_cursor.tp_col = 0;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_backward(teken_t *t, unsigned int ncols)
+{
+
+ if (ncols > t->t_cursor.tp_col)
+ t->t_cursor.tp_col = 0;
+ else
+ t->t_cursor.tp_col -= ncols;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_backward_tabulation(teken_t *t, unsigned int ntabs)
+{
+
+ do {
+ /* Stop when we've reached the beginning of the line. */
+ if (t->t_cursor.tp_col == 0)
+ break;
+
+ t->t_cursor.tp_col--;
+
+ /* Tab marker set. */
+ if (teken_tab_isset(t, t->t_cursor.tp_col))
+ ntabs--;
+ } while (ntabs > 0);
+
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_down(teken_t *t, unsigned int nrows)
+{
+
+ if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end)
+ t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1;
+ else
+ t->t_cursor.tp_row += nrows;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_forward(teken_t *t, unsigned int ncols)
+{
+
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col)
+ t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+ else
+ t->t_cursor.tp_col += ncols;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_forward_tabulation(teken_t *t, unsigned int ntabs)
+{
+
+ do {
+ /* Stop when we've reached the end of the line. */
+ if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1)
+ break;
+
+ t->t_cursor.tp_col++;
+
+ /* Tab marker set. */
+ if (teken_tab_isset(t, t->t_cursor.tp_col))
+ ntabs--;
+ } while (ntabs > 0);
+
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_next_line(teken_t *t, unsigned int ncols)
+{
+
+ t->t_cursor.tp_col = 0;
+ teken_subr_cursor_down(t, ncols);
+}
+
+static void
+teken_subr_cursor_position(teken_t *t, unsigned int row, unsigned int col)
+{
+
+ t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1;
+ if (row >= t->t_originreg.ts_end)
+ t->t_cursor.tp_row = t->t_originreg.ts_end - 1;
+
+ t->t_cursor.tp_col = col - 1;
+ if (t->t_cursor.tp_col >= t->t_winsize.tp_col)
+ t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_cursor_position_report(teken_t *t, unsigned int cmd)
+{
+ char response[18] = "\x1B[";
+ ssize_t len;
+
+ len = teken_subr_do_cpr(t, cmd, response + 2);
+ if (len < 0)
+ return;
+
+ teken_funcs_respond(t, response, len + 2);
+}
+
+static void
+teken_subr_cursor_previous_line(teken_t *t, unsigned int ncols)
+{
+
+ t->t_cursor.tp_col = 0;
+ teken_subr_cursor_up(t, ncols);
+}
+
+static void
+teken_subr_cursor_up(teken_t *t, unsigned int nrows)
+{
+
+ if (t->t_scrollreg.ts_begin + nrows >= t->t_cursor.tp_row)
+ t->t_cursor.tp_row = t->t_scrollreg.ts_begin;
+ else
+ t->t_cursor.tp_row -= nrows;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_delete_character(teken_t *t, unsigned int ncols)
+{
+ teken_rect_t tr;
+
+ tr.tr_begin.tp_row = t->t_cursor.tp_row;
+ tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) {
+ tr.tr_begin.tp_col = t->t_cursor.tp_col;
+ } else {
+ /* Copy characters to the left. */
+ tr.tr_begin.tp_col = t->t_cursor.tp_col + ncols;
+ teken_funcs_copy(t, &tr, &t->t_cursor);
+
+ tr.tr_begin.tp_col = t->t_winsize.tp_col - ncols;
+ }
+
+ /* Blank trailing columns. */
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_delete_line(teken_t *t, unsigned int nrows)
+{
+ teken_rect_t tr;
+
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+
+ if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) {
+ tr.tr_begin.tp_row = t->t_cursor.tp_row;
+ } else {
+ teken_pos_t tp;
+
+ /* Copy rows up. */
+ tr.tr_begin.tp_row = t->t_cursor.tp_row + nrows;
+ tp.tp_row = t->t_cursor.tp_row;
+ tp.tp_col = 0;
+ teken_funcs_copy(t, &tr, &tp);
+
+ tr.tr_begin.tp_row = t->t_scrollreg.ts_end - nrows;
+ }
+
+ /* Blank trailing rows. */
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_device_control_string(teken_t *t __unused)
+{
+
+ teken_printf("device control string???\n");
+}
+
+static void
+teken_subr_device_status_report(teken_t *t, unsigned int cmd)
+{
+ char response[19] = "\x1B[?";
+ ssize_t len;
+
+ len = teken_subr_do_cpr(t, cmd, response + 3);
+ if (len < 0)
+ return;
+
+ teken_funcs_respond(t, response, len + 3);
+}
+
+static void
+teken_subr_double_height_double_width_line_top(teken_t *t __unused)
+{
+
+ teken_printf("double height double width top\n");
+}
+
+static void
+teken_subr_double_height_double_width_line_bottom(teken_t *t __unused)
+{
+
+ teken_printf("double height double width bottom\n");
+}
+
+static void
+teken_subr_erase_character(teken_t *t, unsigned int ncols)
+{
+ teken_rect_t tr;
+
+ tr.tr_begin = t->t_cursor;
+ tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
+
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col)
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ else
+ tr.tr_end.tp_col = t->t_cursor.tp_col + ncols;
+
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_erase_display(teken_t *t, unsigned int mode)
+{
+ teken_rect_t r;
+
+ r.tr_begin.tp_col = 0;
+ r.tr_end.tp_col = t->t_winsize.tp_col;
+
+ switch (mode) {
+ case 1: /* Erase from the top to the cursor. */
+ teken_subr_erase_line(t, 1);
+
+ /* Erase lines above. */
+ if (t->t_cursor.tp_row == 0)
+ return;
+ r.tr_begin.tp_row = 0;
+ r.tr_end.tp_row = t->t_cursor.tp_row;
+ break;
+ case 2: /* Erase entire display. */
+ r.tr_begin.tp_row = 0;
+ r.tr_end.tp_row = t->t_winsize.tp_row;
+ break;
+ default: /* Erase from cursor to the bottom. */
+ teken_subr_erase_line(t, 0);
+
+ /* Erase lines below. */
+ if (t->t_cursor.tp_row == t->t_winsize.tp_row - 1)
+ return;
+ r.tr_begin.tp_row = t->t_cursor.tp_row + 1;
+ r.tr_end.tp_row = t->t_winsize.tp_row;
+ break;
+ }
+
+ teken_funcs_fill(t, &r, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_erase_line(teken_t *t, unsigned int mode)
+{
+ teken_rect_t r;
+
+ r.tr_begin.tp_row = t->t_cursor.tp_row;
+ r.tr_end.tp_row = t->t_cursor.tp_row + 1;
+
+ switch (mode) {
+ case 1: /* Erase from the beginning of the line to the cursor. */
+ r.tr_begin.tp_col = 0;
+ r.tr_end.tp_col = t->t_cursor.tp_col + 1;
+ break;
+ case 2: /* Erase entire line. */
+ r.tr_begin.tp_col = 0;
+ r.tr_end.tp_col = t->t_winsize.tp_col;
+ break;
+ default: /* Erase from cursor to the end of the line. */
+ r.tr_begin.tp_col = t->t_cursor.tp_col;
+ r.tr_end.tp_col = t->t_winsize.tp_col;
+ break;
+ }
+
+ teken_funcs_fill(t, &r, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_g0_scs_special_graphics(teken_t *t __unused)
+{
+
+ teken_scs_set(t, 0, teken_scs_special_graphics);
+}
+
+static void
+teken_subr_g0_scs_uk_national(teken_t *t __unused)
+{
+
+ teken_scs_set(t, 0, teken_scs_uk_national);
+}
+
+static void
+teken_subr_g0_scs_us_ascii(teken_t *t __unused)
+{
+
+ teken_scs_set(t, 0, teken_scs_us_ascii);
+}
+
+static void
+teken_subr_g1_scs_special_graphics(teken_t *t __unused)
+{
+
+ teken_scs_set(t, 1, teken_scs_special_graphics);
+}
+
+static void
+teken_subr_g1_scs_uk_national(teken_t *t __unused)
+{
+
+ teken_scs_set(t, 1, teken_scs_uk_national);
+}
+
+static void
+teken_subr_g1_scs_us_ascii(teken_t *t __unused)
+{
+
+ teken_scs_set(t, 1, teken_scs_us_ascii);
+}
+
+static void
+teken_subr_horizontal_position_absolute(teken_t *t, unsigned int col)
+{
+
+ t->t_cursor.tp_col = col - 1;
+ if (t->t_cursor.tp_col >= t->t_winsize.tp_col)
+ t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_horizontal_tab(teken_t *t)
+{
+#ifdef TEKEN_XTERM
+ teken_rect_t tr;
+
+ tr.tr_begin = t->t_cursor;
+ teken_subr_cursor_forward_tabulation(t, 1);
+ tr.tr_end.tp_row = tr.tr_begin.tp_row + 1;
+ tr.tr_end.tp_col = t->t_cursor.tp_col;
+
+ /* Blank region that we skipped. */
+ if (tr.tr_end.tp_col > tr.tr_begin.tp_col)
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+#else /* !TEKEN_XTERM */
+
+ teken_subr_cursor_forward_tabulation(t, 1);
+#endif /* TEKEN_XTERM */
+}
+
+static void
+teken_subr_horizontal_tab_set(teken_t *t)
+{
+
+ teken_tab_set(t, t->t_cursor.tp_col);
+}
+
+static void
+teken_subr_index(teken_t *t)
+{
+
+ if (t->t_cursor.tp_row < t->t_scrollreg.ts_end - 1) {
+ t->t_cursor.tp_row++;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+ } else {
+ teken_subr_do_scroll(t, 1);
+ }
+}
+
+static void
+teken_subr_insert_character(teken_t *t, unsigned int ncols)
+{
+ teken_rect_t tr;
+
+ tr.tr_begin = t->t_cursor;
+ tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
+
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) {
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ } else {
+ teken_pos_t tp;
+
+ /* Copy characters to the right. */
+ tr.tr_end.tp_col = t->t_winsize.tp_col - ncols;
+ tp.tp_row = t->t_cursor.tp_row;
+ tp.tp_col = t->t_cursor.tp_col + ncols;
+ teken_funcs_copy(t, &tr, &tp);
+
+ tr.tr_end.tp_col = t->t_cursor.tp_col + ncols;
+ }
+
+ /* Blank current location. */
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_insert_line(teken_t *t, unsigned int nrows)
+{
+ teken_rect_t tr;
+
+ tr.tr_begin.tp_row = t->t_cursor.tp_row;
+ tr.tr_begin.tp_col = 0;
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+
+ if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) {
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end;
+ } else {
+ teken_pos_t tp;
+
+ /* Copy lines down. */
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end - nrows;
+ tp.tp_row = t->t_cursor.tp_row + nrows;
+ tp.tp_col = 0;
+ teken_funcs_copy(t, &tr, &tp);
+
+ tr.tr_end.tp_row = t->t_cursor.tp_row + nrows;
+ }
+
+ /* Blank current location. */
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+}
+
+static void
+teken_subr_keypad_application_mode(teken_t *t)
+{
+
+ teken_funcs_param(t, TP_KEYPADAPP, 1);
+}
+
+static void
+teken_subr_keypad_numeric_mode(teken_t *t)
+{
+
+ teken_funcs_param(t, TP_KEYPADAPP, 0);
+}
+
+static void
+teken_subr_newline(teken_t *t)
+{
+
+ t->t_cursor.tp_row++;
+
+ if (t->t_cursor.tp_row >= t->t_scrollreg.ts_end) {
+ teken_subr_do_scroll(t, 1);
+ t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1;
+ }
+
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_newpage(teken_t *t)
+{
+#ifdef TEKEN_XTERM
+
+ teken_subr_newline(t);
+#else /* !TEKEN_XTERM */
+ teken_rect_t tr;
+
+ tr.tr_begin.tp_row = tr.tr_begin.tp_col = 0;
+ tr.tr_end = t->t_winsize;
+ teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
+
+ t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
+ teken_funcs_cursor(t);
+#endif /* TEKEN_XTERM */
+}
+
+static void
+teken_subr_next_line(teken_t *t)
+{
+
+ t->t_cursor.tp_col = 0;
+ teken_subr_newline(t);
+}
+
+static void
+teken_subr_pan_down(teken_t *t, unsigned int nrows)
+{
+
+ teken_subr_do_scroll(t, (int)nrows);
+}
+
+static void
+teken_subr_pan_up(teken_t *t, unsigned int nrows)
+{
+
+ teken_subr_do_scroll(t, -(int)nrows);
+}
+
+static void
+teken_subr_primary_device_attributes(teken_t *t, unsigned int request)
+{
+
+ if (request == 0) {
+ const char response[] = "\x1B[?1;2c";
+
+ teken_funcs_respond(t, response, sizeof response - 1);
+ } else {
+ teken_printf("Unknown DA1\n");
+ }
+}
+
+static void
+teken_subr_do_putchar(teken_t *t, const teken_pos_t *tp, teken_char_t c,
+ int width)
+{
+
+ if (t->t_stateflags & TS_INSERT &&
+ tp->tp_col < t->t_winsize.tp_col - width) {
+ teken_rect_t ctr;
+ teken_pos_t ctp;
+
+ /* Insert mode. Move existing characters to the right. */
+ ctr.tr_begin = *tp;
+ ctr.tr_end.tp_row = tp->tp_row + 1;
+ ctr.tr_end.tp_col = t->t_winsize.tp_col - width;
+ ctp.tp_row = tp->tp_row;
+ ctp.tp_col = tp->tp_col + width;
+ teken_funcs_copy(t, &ctr, &ctp);
+ }
+
+ teken_funcs_putchar(t, tp, c, &t->t_curattr);
+}
+
+static void
+teken_subr_regular_character(teken_t *t, teken_char_t c)
+{
+ int width;
+
+ c = teken_scs_process(t, c);
+
+ /* XXX: Don't process zero-width characters yet. */
+ width = teken_wcwidth(c);
+ if (width <= 0)
+ return;
+
+#ifdef TEKEN_XTERM
+ if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1 &&
+ (t->t_stateflags & (TS_WRAPPED|TS_AUTOWRAP)) ==
+ (TS_WRAPPED|TS_AUTOWRAP)) {
+ teken_pos_t tp;
+
+ /* Perform line wrapping. */
+
+ if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) {
+ /* Perform scrolling. */
+ teken_subr_do_scroll(t, 1);
+ tp.tp_row = t->t_scrollreg.ts_end - 1;
+ } else {
+ /* No scrolling needed. */
+ tp.tp_row = t->t_cursor.tp_row + 1;
+ if (tp.tp_row == t->t_winsize.tp_row) {
+ /*
+ * Corner case: regular character
+ * outside scrolling region, but at the
+ * bottom of the screen.
+ */
+ teken_subr_do_putchar(t, &t->t_cursor,
+ c, width);
+ return;
+ }
+ }
+
+ tp.tp_col = 0;
+ teken_subr_do_putchar(t, &tp, c, width);
+
+ t->t_cursor.tp_row = tp.tp_row;
+ t->t_cursor.tp_col = width;
+ t->t_stateflags &= ~TS_WRAPPED;
+ } else {
+ /* No line wrapping needed. */
+ teken_subr_do_putchar(t, &t->t_cursor, c, width);
+ t->t_cursor.tp_col += width;
+
+ if (t->t_cursor.tp_col >= t->t_winsize.tp_col) {
+ t->t_stateflags |= TS_WRAPPED;
+ t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
+ } else {
+ t->t_stateflags &= ~TS_WRAPPED;
+ }
+ }
+#else /* !TEKEN_XTERM */
+ teken_subr_do_putchar(t, &t->t_cursor, c, width);
+ t->t_cursor.tp_col += width;
+
+ if (t->t_cursor.tp_col >= t->t_winsize.tp_col) {
+ if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) {
+ /* Perform scrolling. */
+ teken_subr_do_scroll(t, 1);
+ } else {
+ /* No scrolling needed. */
+ if (t->t_cursor.tp_row < t->t_winsize.tp_row - 1)
+ t->t_cursor.tp_row++;
+ }
+ t->t_cursor.tp_col = 0;
+ }
+#endif /* TEKEN_XTERM */
+
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_reset_dec_mode(teken_t *t, unsigned int cmd)
+{
+
+ switch (cmd) {
+ case 1: /* Cursor keys mode. */
+ teken_funcs_param(t, TP_CURSORKEYS, 0);
+ break;
+ case 2: /* DECANM: ANSI/VT52 mode. */
+ teken_printf("DECRST VT52\n");
+ break;
+ case 3: /* 132 column mode. */
+ teken_funcs_param(t, TP_132COLS, 0);
+ teken_subr_reset_to_initial_state(t);
+ break;
+ case 5: /* Inverse video. */
+ teken_printf("DECRST inverse video\n");
+ break;
+ case 6: /* Origin mode. */
+ t->t_stateflags &= ~TS_ORIGIN;
+ t->t_originreg.ts_begin = 0;
+ t->t_originreg.ts_end = t->t_winsize.tp_row;
+ t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+ break;
+ case 7: /* Autowrap mode. */
+ t->t_stateflags &= ~TS_AUTOWRAP;
+ break;
+ case 8: /* Autorepeat mode. */
+ teken_funcs_param(t, TP_AUTOREPEAT, 0);
+ break;
+ case 25: /* Hide cursor. */
+ teken_funcs_param(t, TP_SHOWCURSOR, 0);
+ break;
+ case 40: /* Disallow 132 columns. */
+ teken_printf("DECRST allow 132\n");
+ break;
+ case 45: /* Disable reverse wraparound. */
+ teken_printf("DECRST reverse wraparound\n");
+ break;
+ case 47: /* Switch to alternate buffer. */
+ teken_printf("Switch to alternate buffer\n");
+ break;
+ default:
+ teken_printf("Unknown DECRST: %u\n", cmd);
+ }
+}
+
+static void
+teken_subr_reset_mode(teken_t *t, unsigned int cmd)
+{
+
+ switch (cmd) {
+ case 4:
+ t->t_stateflags &= ~TS_INSERT;
+ break;
+ default:
+ teken_printf("Unknown reset mode: %u\n", cmd);
+ }
+}
+
+static void
+teken_subr_do_reset(teken_t *t)
+{
+
+ t->t_curattr = t->t_defattr;
+ t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
+ t->t_stateflags = TS_AUTOWRAP;
+
+ teken_scs_set(t, 0, teken_scs_us_ascii);
+ teken_scs_set(t, 1, teken_scs_us_ascii);
+ teken_scs_switch(t, 0);
+
+ teken_subr_save_cursor(t);
+ teken_tab_default(t);
+}
+
+static void
+teken_subr_reset_to_initial_state(teken_t *t)
+{
+
+ teken_subr_do_reset(t);
+ teken_subr_erase_display(t, 2);
+ teken_funcs_param(t, TP_SHOWCURSOR, 1);
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_restore_cursor(teken_t *t)
+{
+
+ t->t_cursor = t->t_saved_cursor;
+ t->t_curattr = t->t_saved_curattr;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_scs_restore(t);
+ teken_funcs_cursor(t);
+}
+
+static void
+teken_subr_reverse_index(teken_t *t)
+{
+
+ if (t->t_cursor.tp_row > t->t_scrollreg.ts_begin) {
+ t->t_cursor.tp_row--;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+ } else {
+ teken_subr_do_scroll(t, -1);
+ }
+}
+
+static void
+teken_subr_save_cursor(teken_t *t)
+{
+
+ t->t_saved_cursor = t->t_cursor;
+ t->t_saved_curattr = t->t_curattr;
+ teken_scs_save(t);
+}
+
+static void
+teken_subr_secondary_device_attributes(teken_t *t, unsigned int request)
+{
+
+ if (request == 0) {
+ const char response[] = "\x1B[>0;10;0c";
+ teken_funcs_respond(t, response, sizeof response - 1);
+ } else {
+ teken_printf("Unknown DA2\n");
+ }
+}
+
+static void
+teken_subr_set_dec_mode(teken_t *t, unsigned int cmd)
+{
+
+ switch (cmd) {
+ case 1: /* Cursor keys mode. */
+ teken_funcs_param(t, TP_CURSORKEYS, 1);
+ break;
+ case 2: /* DECANM: ANSI/VT52 mode. */
+ teken_printf("DECSET VT52\n");
+ break;
+ case 3: /* 132 column mode. */
+ teken_funcs_param(t, TP_132COLS, 1);
+ teken_subr_reset_to_initial_state(t);
+ break;
+ case 5: /* Inverse video. */
+ teken_printf("DECSET inverse video\n");
+ break;
+ case 6: /* Origin mode. */
+ t->t_stateflags |= TS_ORIGIN;
+ t->t_originreg = t->t_scrollreg;
+ t->t_cursor.tp_row = t->t_scrollreg.ts_begin;
+ t->t_cursor.tp_col = 0;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+ break;
+ case 7: /* Autowrap mode. */
+ t->t_stateflags |= TS_AUTOWRAP;
+ break;
+ case 8: /* Autorepeat mode. */
+ teken_funcs_param(t, TP_AUTOREPEAT, 1);
+ break;
+ case 25: /* Display cursor. */
+ teken_funcs_param(t, TP_SHOWCURSOR, 1);
+ break;
+ case 40: /* Allow 132 columns. */
+ teken_printf("DECSET allow 132\n");
+ break;
+ case 45: /* Enable reverse wraparound. */
+ teken_printf("DECSET reverse wraparound\n");
+ break;
+ case 47: /* Switch to alternate buffer. */
+ teken_printf("Switch away from alternate buffer\n");
+ break;
+ default:
+ teken_printf("Unknown DECSET: %u\n", cmd);
+ }
+}
+
+static void
+teken_subr_set_mode(teken_t *t, unsigned int cmd)
+{
+
+ switch (cmd) {
+ case 4:
+ teken_printf("Insert mode\n");
+ t->t_stateflags |= TS_INSERT;
+ break;
+ default:
+ teken_printf("Unknown set mode: %u\n", cmd);
+ }
+}
+
+static void
+teken_subr_set_graphic_rendition(teken_t *t, unsigned int ncmds,
+ unsigned int cmds[])
+{
+ unsigned int i, n;
+
+ /* No attributes means reset. */
+ if (ncmds == 0) {
+ t->t_curattr = t->t_defattr;
+ return;
+ }
+
+ for (i = 0; i < ncmds; i++) {
+ n = cmds[i];
+
+ switch (n) {
+ case 0: /* Reset. */
+ t->t_curattr = t->t_defattr;
+ break;
+ case 1: /* Bold. */
+ t->t_curattr.ta_format |= TF_BOLD;
+ break;
+ case 4: /* Underline. */
+ t->t_curattr.ta_format |= TF_UNDERLINE;
+ break;
+ case 5: /* Blink. */
+ t->t_curattr.ta_format |= TF_BLINK;
+ break;
+ case 7: /* Reverse. */
+ t->t_curattr.ta_format |= TF_REVERSE;
+ break;
+ case 22: /* Remove bold. */
+ t->t_curattr.ta_format &= ~TF_BOLD;
+ break;
+ case 24: /* Remove underline. */
+ t->t_curattr.ta_format &= ~TF_UNDERLINE;
+ break;
+ case 25: /* Remove blink. */
+ t->t_curattr.ta_format &= ~TF_BLINK;
+ break;
+ case 27: /* Remove reverse. */
+ t->t_curattr.ta_format &= ~TF_REVERSE;
+ break;
+ case 30: /* Set foreground color: black */
+ case 31: /* Set foreground color: red */
+ case 32: /* Set foreground color: green */
+ case 33: /* Set foreground color: brown */
+ case 34: /* Set foreground color: blue */
+ case 35: /* Set foreground color: magenta */
+ case 36: /* Set foreground color: cyan */
+ case 37: /* Set foreground color: white */
+ t->t_curattr.ta_fgcolor = n - 30;
+ break;
+ case 39: /* Set default foreground color. */
+ t->t_curattr.ta_fgcolor = t->t_defattr.ta_fgcolor;
+ break;
+ case 40: /* Set background color: black */
+ case 41: /* Set background color: red */
+ case 42: /* Set background color: green */
+ case 43: /* Set background color: brown */
+ case 44: /* Set background color: blue */
+ case 45: /* Set background color: magenta */
+ case 46: /* Set background color: cyan */
+ case 47: /* Set background color: white */
+ t->t_curattr.ta_bgcolor = n - 40;
+ break;
+ case 49: /* Set default background color. */
+ t->t_curattr.ta_bgcolor = t->t_defattr.ta_bgcolor;
+ break;
+ default:
+ teken_printf("unsupported attribute %u\n", n);
+ }
+ }
+}
+
+static void
+teken_subr_set_top_and_bottom_margins(teken_t *t, unsigned int top,
+ unsigned int bottom)
+{
+
+ /* Adjust top row number. */
+ if (top > 0)
+ top--;
+ /* Adjust bottom row number. */
+ if (bottom == 0 || bottom > t->t_winsize.tp_row)
+ bottom = t->t_winsize.tp_row;
+
+ /* Invalid arguments. */
+ if (top >= bottom - 1) {
+ top = 0;
+ bottom = t->t_winsize.tp_row;
+ }
+
+ t->t_scrollreg.ts_begin = top;
+ t->t_scrollreg.ts_end = bottom;
+ if (t->t_stateflags & TS_ORIGIN) {
+ /* XXX: home cursor? */
+ t->t_originreg = t->t_scrollreg;
+ t->t_cursor.tp_row = t->t_originreg.ts_begin;
+ t->t_cursor.tp_col = 0;
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+ }
+}
+
+static void
+teken_subr_single_height_double_width_line(teken_t *t __unused)
+{
+
+ teken_printf("single height double width???\n");
+}
+
+static void
+teken_subr_single_height_single_width_line(teken_t *t __unused)
+{
+
+ teken_printf("single height single width???\n");
+}
+
+static void
+teken_subr_string_terminator(teken_t *t __unused)
+{
+
+ teken_printf("string terminator???\n");
+}
+
+static void
+teken_subr_tab_clear(teken_t *t, unsigned int cmd)
+{
+
+ switch (cmd) {
+ case 0:
+ teken_tab_clear(t, t->t_cursor.tp_col);
+ break;
+ case 3:
+ memset(&t->t_tabstops, 0, T_NUMCOL / 8);
+ break;
+ }
+}
+
+static void
+teken_subr_vertical_position_absolute(teken_t *t, unsigned int row)
+{
+
+ t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1;
+ if (row >= t->t_originreg.ts_end)
+ t->t_cursor.tp_row = t->t_originreg.ts_end - 1;
+
+
+ t->t_stateflags &= ~TS_WRAPPED;
+ teken_funcs_cursor(t);
+}
diff --git a/sys/dev/syscons/teken/teken_subr_compat.h b/sys/dev/syscons/teken/teken_subr_compat.h
new file mode 100644
index 000000000000..e49c1cd5696f
--- /dev/null
+++ b/sys/dev/syscons/teken/teken_subr_compat.h
@@ -0,0 +1,77 @@
+/*-
+ * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+static void
+teken_subr_cons25_set_cursor_type(teken_t *t, unsigned int type)
+{
+
+ teken_funcs_param(t, TP_SHOWCURSOR, type != 1);
+}
+
+static const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
+ TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_BROWN, TC_WHITE };
+
+static void
+teken_subr_cons25_set_adapter_background(teken_t *t, unsigned int c)
+{
+
+ t->t_defattr.ta_bgcolor = cons25_colors[c % 8];
+ t->t_curattr.ta_bgcolor = cons25_colors[c % 8];
+}
+
+static void
+teken_subr_cons25_set_adapter_foreground(teken_t *t, unsigned int c)
+{
+
+ t->t_defattr.ta_fgcolor = cons25_colors[c % 8];
+ t->t_curattr.ta_fgcolor = cons25_colors[c % 8];
+ if (c >= 8) {
+ t->t_defattr.ta_format |= TF_BOLD;
+ t->t_curattr.ta_format |= TF_BOLD;
+ } else {
+ t->t_defattr.ta_format &= ~TF_BOLD;
+ t->t_curattr.ta_format &= ~TF_BOLD;
+ }
+}
+
+static void
+teken_subr_cons25_switch_virtual_terminal(teken_t *t, unsigned int vt)
+{
+
+ teken_funcs_param(t, TP_SWITCHVT, vt);
+}
+
+#if 0
+static void
+teken_subr_vt52_decid(teken_t *t)
+{
+ const char response[] = "\x1B/Z";
+
+ teken_funcs_respond(t, response, sizeof response - 1);
+}
+#endif
diff --git a/sys/dev/syscons/teken/teken_wcwidth.h b/sys/dev/syscons/teken/teken_wcwidth.h
new file mode 100644
index 000000000000..838fb3dac422
--- /dev/null
+++ b/sys/dev/syscons/teken/teken_wcwidth.h
@@ -0,0 +1,120 @@
+/*
+ * Markus Kuhn -- 2007-05-26 (Unicode 5.0)
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * for any purpose and without fee is hereby granted. The author
+ * disclaims all warranties with regard to this software.
+ *
+ * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
+ *
+ * $FreeBSD$
+ */
+
+struct interval {
+ teken_char_t first;
+ teken_char_t last;
+};
+
+/* auxiliary function for binary search in interval table */
+static int bisearch(teken_char_t ucs, const struct interval *table, int max) {
+ int min = 0;
+ int mid;
+
+ if (ucs < table[0].first || ucs > table[max].last)
+ return 0;
+ while (max >= min) {
+ mid = (min + max) / 2;
+ if (ucs > table[mid].last)
+ min = mid + 1;
+ else if (ucs < table[mid].first)
+ max = mid - 1;
+ else
+ return 1;
+ }
+
+ return 0;
+}
+
+static int teken_wcwidth(teken_char_t ucs)
+{
+ /* sorted list of non-overlapping intervals of non-spacing characters */
+ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
+ static const struct interval combining[] = {
+ { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 },
+ { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
+ { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 },
+ { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 },
+ { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
+ { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
+ { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 },
+ { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D },
+ { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 },
+ { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD },
+ { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C },
+ { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D },
+ { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC },
+ { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD },
+ { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C },
+ { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D },
+ { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
+ { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
+ { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC },
+ { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
+ { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D },
+ { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
+ { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
+ { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC },
+ { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 },
+ { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E },
+ { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 },
+ { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 },
+ { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 },
+ { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F },
+ { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 },
+ { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD },
+ { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD },
+ { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 },
+ { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B },
+ { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 },
+ { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 },
+ { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF },
+ { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 },
+ { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F },
+ { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B },
+ { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F },
+ { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB },
+ { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F },
+ { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 },
+ { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD },
+ { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F },
+ { 0xE0100, 0xE01EF }
+ };
+
+ /* test for 8-bit control characters */
+ if (ucs == 0)
+ return 0;
+ if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
+ return -1;
+
+ /* binary search in table of non-spacing characters */
+ if (bisearch(ucs, combining,
+ sizeof(combining) / sizeof(struct interval) - 1))
+ return 0;
+
+ /* if we arrive here, ucs is not a combining or C0/C1 control character */
+
+ return 1 +
+ (ucs >= 0x1100 &&
+ (ucs <= 0x115f || /* Hangul Jamo init. consonants */
+ ucs == 0x2329 || ucs == 0x232a ||
+ (ucs >= 0x2e80 && ucs <= 0xa4cf &&
+ ucs != 0x303f) || /* CJK ... Yi */
+ (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
+ (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
+ (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */
+ (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
+ (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
+ (ucs >= 0xffe0 && ucs <= 0xffe6) ||
+ (ucs >= 0x20000 && ucs <= 0x2fffd) ||
+ (ucs >= 0x30000 && ucs <= 0x3fffd)));
+}
diff --git a/sys/dev/syscons/warp/warp_saver.c b/sys/dev/syscons/warp/warp_saver.c
new file mode 100644
index 000000000000..85a7d29b03cd
--- /dev/null
+++ b/sys/dev/syscons/warp/warp_saver.c
@@ -0,0 +1,167 @@
+/*-
+ * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/syslog.h>
+#include <sys/consio.h>
+#include <sys/fbio.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define SAVER_NAME "warp_saver"
+#define SPP 15
+#define STARS (SPP * (1 + 2 + 4 + 8))
+
+#define SET_ORIGIN(adp, o) do { \
+ int oo = o; \
+ if (oo != last_origin) \
+ vidd_set_win_org(adp, last_origin = oo); \
+ } while (0)
+
+static u_char *vid;
+static int banksize, scrmode, bpsl, scrw, scrh;
+static int blanked;
+static int star[STARS];
+static u_char warp_pal[768] = {
+ 0x00, 0x00, 0x00,
+ 0x66, 0x66, 0x66,
+ 0x99, 0x99, 0x99,
+ 0xcc, 0xcc, 0xcc,
+ 0xff, 0xff, 0xff
+ /* the rest is zero-filled by the compiler */
+};
+
+static void
+warp_update(video_adapter_t *adp)
+{
+ int i, j, k, n, o, p;
+ int last_origin = -1;
+
+ for (i = 1, k = 0, n = SPP*8; i < 5; i++, n /= 2) {
+ for (j = 0; j < n; j++, k++) {
+ p = (star[k] / scrw) * bpsl + (star[k] % scrw);
+ o = 0;
+ while (p > banksize) {
+ p -= banksize;
+ o += banksize;
+ }
+ SET_ORIGIN(adp, o);
+ vid[p] = 0;
+ star[k] += i;
+ if (star[k] > scrw*scrh)
+ star[k] -= scrw*scrh;
+ p = (star[k] / scrw) * bpsl + (star[k] % scrw);
+ o = 0;
+ while (p > banksize) {
+ p -= banksize;
+ o += banksize;
+ }
+ SET_ORIGIN(adp, o);
+ vid[p] = i;
+ }
+ }
+}
+
+static int
+warp_saver(video_adapter_t *adp, int blank)
+{
+ int pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ vidd_set_mode(adp, scrmode);
+ vidd_load_palette(adp, warp_pal);
+ vidd_set_border(adp, 0);
+ blanked++;
+ vid = (u_char *)adp->va_window;
+ banksize = adp->va_window_size;
+ bpsl = adp->va_line_width;
+ splx(pl);
+ vidd_clear(adp);
+ }
+ /* update display */
+ warp_update(adp);
+ } else {
+ blanked = 0;
+ }
+ return (0);
+}
+
+static int
+warp_init(video_adapter_t *adp)
+{
+ video_info_t info;
+ int i;
+
+ if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
+ scrmode = M_VGA_CG320;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
+ scrmode = M_PC98_PEGC640x480;
+ } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
+ scrmode = M_PC98_PEGC640x400;
+ } else {
+ log(LOG_NOTICE,
+ "%s: the console does not support M_VGA_CG320\n",
+ SAVER_NAME);
+ return (ENODEV);
+ }
+
+ scrw = info.vi_width;
+ scrh = info.vi_height;
+
+ /* randomize the star field */
+ for (i = 0; i < STARS; i++)
+ star[i] = random() % (scrw * scrh);
+
+ return (0);
+}
+
+static int
+warp_term(video_adapter_t *adp)
+{
+ return (0);
+}
+
+static scrn_saver_t warp_module = {
+ SAVER_NAME,
+ warp_init,
+ warp_term,
+ warp_saver,
+ NULL
+};
+
+SAVER_MODULE(warp_saver, warp_module);