summaryrefslogtreecommitdiffstats
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.c91
-rw-r--r--sys/dev/syscons/blank/blank_saver.c69
-rw-r--r--sys/dev/syscons/daemon/daemon_saver.c393
-rw-r--r--sys/dev/syscons/fade/fade_saver.c105
-rw-r--r--sys/dev/syscons/fire/fire_saver.c136
-rw-r--r--sys/dev/syscons/green/green_saver.c69
-rw-r--r--sys/dev/syscons/logo/logo.c352
-rw-r--r--sys/dev/syscons/logo/logo_saver.c157
-rw-r--r--sys/dev/syscons/rain/rain_saver.c131
-rw-r--r--sys/dev/syscons/scgfbrndr.c829
-rw-r--r--sys/dev/syscons/schistory.c307
-rw-r--r--sys/dev/syscons/scmouse.c1071
-rw-r--r--sys/dev/syscons/scvesactl.c141
-rw-r--r--sys/dev/syscons/scvgarndr.c829
-rw-r--r--sys/dev/syscons/scvidctl.c789
-rw-r--r--sys/dev/syscons/scvtb.c301
-rw-r--r--sys/dev/syscons/snake/snake_saver.c148
-rw-r--r--sys/dev/syscons/star/star_saver.c135
-rw-r--r--sys/dev/syscons/syscons.c4046
-rw-r--r--sys/dev/syscons/syscons.h511
-rw-r--r--sys/dev/syscons/warp/warp_saver.c139
21 files changed, 10749 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 0000000..d7863ba
--- /dev/null
+++ b/sys/dev/syscons/apm/apm_saver.c
@@ -0,0 +1,91 @@
+/*-
+ * 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/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>
+
+#include <sys/select.h>
+#include <machine/apm_bios.h>
+#include <machine/pc/bios.h>
+#include <i386/apm/apm.h>
+
+extern int apm_display __P((int newstate));
+
+extern struct apm_softc apm_softc;
+
+static int blanked=0;
+
+static int
+apm_saver(video_adapter_t *adp, int blank)
+{
+ struct apm_softc *sc = &apm_softc;
+
+ if (!sc->initialized || !sc->active)
+ return 0;
+
+ if (blank==blanked)
+ return 0;
+
+ blanked=blank;
+
+ apm_display(!blanked);
+
+ return 0;
+}
+
+static int
+apm_init(video_adapter_t *adp)
+{
+ struct apm_softc *sc = &apm_softc;
+
+ if (!sc->initialized || !sc->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);
diff --git a/sys/dev/syscons/blank/blank_saver.c b/sys/dev/syscons/blank/blank_saver.c
new file mode 100644
index 0000000..960acca
--- /dev/null
+++ b/sys/dev/syscons/blank/blank_saver.c
@@ -0,0 +1,69 @@
+/*-
+ * 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)
+{
+ (*vidsw[adp->va_index]->blank_display)(adp,
+ (blank) ? V_DISPLAY_BLANK
+ : V_DISPLAY_ON);
+ return 0;
+}
+
+static int
+blank_init(video_adapter_t *adp)
+{
+ if ((*vidsw[adp->va_index]->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 0000000..bc03f64
--- /dev/null
+++ b/sys/dev/syscons/daemon/daemon_saver.c
@@ -0,0 +1,393 @@
+/*-
+ * 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/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 char *message;
+static int messagelen;
+static int blanked;
+
+/* Who is the author of this ASCII pic? */
+
+static char *daemon_pic[] = {
+ " , ,",
+ " /( )`",
+ " \\ \\___ / |",
+ " /- _ `-/ '",
+ " (/\\/ \\ \\ /\\",
+ " / / | ` \\",
+ " O O ) / |",
+ " `-^--'`< '",
+ " (_.) _ ) /",
+ " `.___/` /",
+ " `-----' /",
+ "<----. __ / __ \\",
+ "<----|====O)))==) \\) /====",
+ "<----' `--' `.__,' \\",
+ " | |",
+ " \\ / /\\",
+ " ______( (_ / \\______/",
+ " ,' ,-----' |",
+ " `--{__________)",
+ NULL
+};
+
+static 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 char
+xflip_symbol(char symbol)
+{
+ static const char lchars[] = "`'(){}[]\\/<>";
+ static const 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], (FG_LIGHTGREY | BG_BLACK) << 8);
+ }
+}
+
+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]) {
+#ifndef PC98
+ case 'R': attr = (FG_LIGHTRED|BG_BLACK)<<8; break;
+ case 'Y': attr = (FG_YELLOW|BG_BLACK)<<8; break;
+ case 'B': attr = (FG_LIGHTBLUE|BG_BLACK)<<8; break;
+ case 'W': attr = (FG_LIGHTGREY|BG_BLACK)<<8; break;
+ case 'C': attr = (FG_CYAN|BG_BLACK)<<8; break;
+ default: attr = (FG_WHITE|BG_BLACK)<<8; break;
+#else /* PC98 */
+ case 'R': attr = (FG_RED|BG_BLACK)<<8; break;
+ case 'Y': attr = (FG_BROWN|BG_BLACK)<<8; break;
+ case 'B': attr = (FG_BLUE|BG_BLACK)<<8; break;
+ case 'W': attr = (FG_LIGHTGREY|BG_BLACK)<<8; break;
+ case 'C': attr = (FG_CYAN|BG_BLACK)<<8; break;
+ default: attr = (FG_LIGHTGREY|BG_BLACK)<<8; break;
+#endif /* PC98 */
+ }
+ 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);
+ } 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);
+ }
+ }
+ }
+}
+
+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], (FG_LIGHTGREY | BG_BLACK) << 8);
+}
+
+static void
+draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, 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]], (FG_LIGHTGREEN | BG_BLACK) << 8);
+ }
+}
+
+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) {
+#ifdef PC98
+ if (epson_machine_id == 0x20) {
+ outb(0x43f, 0x42);
+ outb(0x0c17, inb(0xc17) & ~0x08);
+ outb(0x43f, 0x40);
+ }
+#endif /* PC98 */
+ /* clear the screen and set the border color */
+ sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
+ 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, (char *)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, (char *)message, tlen);
+ } else {
+#ifdef PC98
+ if (epson_machine_id == 0x20) {
+ outb(0x43f, 0x42);
+ outb(0x0c17, inb(0xc17) | 0x08);
+ outb(0x43f, 0x40);
+ }
+#endif /* PC98 */
+ blanked = 0;
+ }
+ return 0;
+}
+
+static int
+daemon_init(video_adapter_t *adp)
+{
+ messagelen = strlen(hostname) + 3 + strlen(ostype) + 1 +
+ strlen(osrelease);
+ message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
+ sprintf(message, "%s - %s %s", hostname, ostype, osrelease);
+ blanked = 0;
+ 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/fade/fade_saver.c b/sys/dev/syscons/fade/fade_saver.c
new file mode 100644
index 0000000..052fa92
--- /dev/null
+++ b/sys/dev/syscons/fade/fade_saver.c
@@ -0,0 +1,105 @@
+/*-
+ * 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 blanked;
+
+static int
+fade_saver(video_adapter_t *adp, int blank)
+{
+ static int count = 0;
+ u_char pal[256*3];
+ int i;
+
+ if (blank) {
+ blanked = TRUE;
+ if (ISPALAVAIL(adp->va_flags)) {
+ if (count <= 0)
+ 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;
+ }
+ load_palette(adp, pal);
+ count++;
+ }
+ } else {
+ (*vidsw[adp->va_index]->blank_display)(adp,
+ V_DISPLAY_BLANK);
+ }
+ } else {
+ if (ISPALAVAIL(adp->va_flags)) {
+ load_palette(adp, palette);
+ count = 0;
+ } else {
+ (*vidsw[adp->va_index]->blank_display)(adp,
+ V_DISPLAY_ON);
+ }
+ blanked = FALSE;
+ }
+ return 0;
+}
+
+static int
+fade_init(video_adapter_t *adp)
+{
+ if (!ISPALAVAIL(adp->va_flags)
+ && (*vidsw[adp->va_index]->blank_display)(adp, V_DISPLAY_ON) != 0)
+ return ENODEV;
+ blanked = FALSE;
+ 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 0000000..59c7079
--- /dev/null
+++ b/sys/dev/syscons/fire/fire_saver.c
@@ -0,0 +1,136 @@
+/*-
+ * 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/fbio.h>
+
+#include <machine/random.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+#define X_SIZE 320
+#define Y_SIZE 200
+
+static int blanked;
+static u_char fire_pal[768];
+static u_char buf[X_SIZE * (Y_SIZE + 1)];
+static u_char *vid;
+
+static int
+fire_saver(video_adapter_t *adp, int blank)
+{
+ int x, y;
+
+ if (blank) {
+ if (blanked <= 0) {
+ int red, green, blue;
+ int palette_index;
+
+ set_video_mode(adp, M_VGA_CG320);
+
+ /* build and load palette */
+ red = green = blue = 0;
+ for (palette_index = 0; palette_index < 256; palette_index++) {
+ red++;
+ if (red > 128)
+ green += 2;
+
+ fire_pal[(palette_index * 3) + 0] = red;
+ fire_pal[(palette_index * 3) + 1] = green;
+ fire_pal[(palette_index * 3) + 2] = blue;
+ }
+ load_palette(adp, fire_pal);
+
+ blanked++;
+ vid = (u_char *) adp->va_window;
+ }
+ /* make a new bottom line */
+ for (x = 0, y = Y_SIZE; x < X_SIZE; x++)
+ buf[x + (y * X_SIZE)] = random() % 160 + 96;
+
+ /* fade the flames out */
+ for (y = 0; y < Y_SIZE; y++) {
+ for (x = 0; x < X_SIZE; x++) {
+ buf[x + (y * X_SIZE)] = (buf[(x + 0) + ((y + 0) * X_SIZE)] +
+ buf[(x - 1) + ((y + 1) * X_SIZE)] +
+ buf[(x + 0) + ((y + 1) * X_SIZE)] +
+ buf[(x + 1) + ((y + 1) * X_SIZE)]) / 4;
+ if (buf[x + (y * X_SIZE)] > 0)
+ buf[x + (y * X_SIZE)]--;
+ }
+ }
+
+ /* blit our buffer into video ram */
+ memcpy(vid, buf, X_SIZE * Y_SIZE);
+ } else {
+ blanked = 0;
+ }
+
+ return 0;
+}
+
+static int
+fire_initialise(video_adapter_t *adp)
+{
+ video_info_t info;
+
+ /* check that the console is capable of running in 320x200x256 */
+ if (get_mode_info(adp, M_VGA_CG320, &info)) {
+ log(LOG_NOTICE, "fire_saver: the console does not support M_VGA_CG320\n");
+ return (ENODEV);
+ }
+ blanked = 0;
+
+ return 0;
+}
+
+static int
+fire_terminate(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t fire_module = {
+ "fire_saver", fire_initialise, fire_terminate, 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 0000000..d6cfe80
--- /dev/null
+++ b/sys/dev/syscons/green/green_saver.c
@@ -0,0 +1,69 @@
+/*-
+ * 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)
+{
+ (*vidsw[adp->va_index]->blank_display)(adp,
+ (blank) ? V_DISPLAY_STAND_BY
+ : V_DISPLAY_ON);
+ return 0;
+}
+
+static int
+green_init(video_adapter_t *adp)
+{
+ if ((*vidsw[adp->va_index]->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 0000000..be502fe
--- /dev/null
+++ b/sys/dev/syscons/logo/logo.c
@@ -0,0 +1,352 @@
+#define logo_w 88
+#define logo_h 88
+
+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_w*logo_h] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
+};
diff --git a/sys/dev/syscons/logo/logo_saver.c b/sys/dev/syscons/logo/logo_saver.c
new file mode 100644
index 0000000..2d2c660
--- /dev/null
+++ b/sys/dev/syscons/logo/logo_saver.c
@@ -0,0 +1,157 @@
+/*-
+ * 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>
+
+static u_char *vid;
+static int banksize, scrmode, bpsl, scrw, scrh;
+static int blanked;
+
+#include "logo.c"
+
+static void
+logo_blit(video_adapter_t *adp, int x, int y)
+{
+ int d, l, o, p;
+
+ for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
+ o += banksize;
+ set_origin(adp, o);
+
+ for (d = 0; d < sizeof logo_img; 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 i, pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ set_video_mode(adp, scrmode);
+ load_palette(adp, logo_pal);
+#if 0 /* XXX conflict */
+ set_border(adp, 0);
+#endif
+ 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);
+ bzero(vid, banksize);
+ }
+ }
+ logo_update(adp);
+ } else {
+ blanked = 0;
+ }
+ return 0;
+}
+
+static int
+logo_init(video_adapter_t *adp)
+{
+ video_info_t info;
+
+ if (!get_mode_info(adp, M_VESA_CG800x600, &info)) {
+ scrmode = M_VESA_CG800x600;
+ } else if (!get_mode_info(adp, M_VGA_CG320, &info)) {
+ scrmode = M_VGA_CG320;
+ } else {
+ log(LOG_NOTICE, "logo_saver: no suitable graphics mode\n");
+ return ENODEV;
+ }
+
+ scrw = info.vi_width;
+ scrh = info.vi_height;
+ blanked = 0;
+
+ return 0;
+}
+
+static int
+logo_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t logo_module = {
+ "logo_saver", 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 0000000..6d2ed39
--- /dev/null
+++ b/sys/dev/syscons/rain/rain_saver.c
@@ -0,0 +1,131 @@
+/*-
+ * 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 <machine/random.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+static u_char *vid;
+
+#define SCRW 320
+#define SCRH 200
+#define MAX 63
+
+static u_char rain_pal[768];
+static int blanked;
+
+static void
+rain_update(video_adapter_t *adp)
+{
+ int i, t;
+
+ t = rain_pal[(MAX*3+2)];
+ for (i = (MAX*3+2); i > 5; i -= 3)
+ rain_pal[i] = rain_pal[i-3];
+ rain_pal[5] = t;
+ load_palette(adp, rain_pal);
+}
+
+static int
+rain_saver(video_adapter_t *adp, int blank)
+{
+ int i, j, k, pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ set_video_mode(adp, M_VGA_CG320);
+ load_palette(adp, rain_pal);
+#if 0 /* XXX conflict */
+ set_border(adp, 0);
+#endif
+ blanked++;
+ vid = (u_char *)adp->va_window;
+ splx(pl);
+ bzero(vid, SCRW*SCRH);
+ for (i = 0; i < SCRW; i += 2)
+ vid[i] = 1 + (random() % MAX);
+ for (j = 1, k = SCRW; j < SCRH; j++)
+ for (i = 0; i < SCRW; i += 2, k += 2)
+ vid[k] = (vid[k-SCRW] < MAX) ? 1 + vid[k-SCRW] : 1;
+ }
+
+ /* update display */
+ rain_update(adp);
+
+ } else {
+ blanked = 0;
+ }
+ return 0;
+}
+
+static int
+rain_init(video_adapter_t *adp)
+{
+ video_info_t info;
+ int i;
+
+ /* check that the console is capable of running in 320x200x256 */
+ if (get_mode_info(adp, M_VGA_CG320, &info)) {
+ log(LOG_NOTICE, "rain_saver: the console does not support M_VGA_CG320\n");
+ return ENODEV;
+ }
+
+ /* intialize the palette */
+ for (i = 3; i < (MAX+1)*3; i += 3)
+ rain_pal[i+2] = rain_pal[i-1] + 4;
+
+ blanked = 0;
+
+ return 0;
+}
+
+static int
+rain_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t rain_module = {
+ "rain_saver", 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 0000000..8a1cdaa
--- /dev/null
+++ b/sys/dev/syscons/scgfbrndr.c
@@ -0,0 +1,829 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include "sc.h"
+#include "vga.h"
+#include "opt_syscons.h"
+#include "opt_vga.h"
+
+#if NSC > 0 && NVGA > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <machine/console.h>
+#include <machine/md_var.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/vgareg.h>
+#include <dev/syscons/syscons.h>
+
+#include <isa/isareg.h>
+
+#ifndef SC_MOUSE_CHAR
+#define SC_MOUSE_CHAR (0xd0)
+#endif
+
+#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_clear_t vga_pxlclear;
+static vr_draw_border_t vga_pxlborder;
+static vr_draw_t vga_egadraw;
+static vr_draw_t vga_vgadraw;
+static vr_set_cursor_t vga_pxlcursor_shape;
+static vr_draw_cursor_t vga_pxlcursor;
+static vr_blink_cursor_t vga_pxlblink;
+#ifndef SC_NO_CUTPASTE
+static vr_draw_mouse_t vga_pxlmouse;
+#else
+#define vga_pxlmouse (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 = {
+ 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);
+RENDERER(cga, 0, txtrndrsw);
+RENDERER(ega, 0, txtrndrsw);
+RENDERER(vga, 0, txtrndrsw);
+
+#ifdef SC_PIXEL_MODE
+static sc_rndr_sw_t egarndrsw = {
+ vga_pxlclear,
+ vga_pxlborder,
+ vga_egadraw,
+ vga_pxlcursor_shape,
+ vga_pxlcursor,
+ vga_pxlblink,
+ (vr_set_mouse_t *)vga_nop,
+ vga_pxlmouse,
+};
+RENDERER(ega, PIXEL_MODE, egarndrsw);
+
+static sc_rndr_sw_t vgarndrsw = {
+ vga_pxlclear,
+ vga_pxlborder,
+ vga_vgadraw,
+ vga_pxlcursor_shape,
+ vga_pxlcursor,
+ vga_pxlblink,
+ (vr_set_mouse_t *)vga_nop,
+ vga_pxlmouse,
+};
+RENDERER(vga, PIXEL_MODE, vgarndrsw);
+#endif /* SC_PIXEL_MODE */
+
+#ifndef SC_NO_MODE_CHANGE
+static sc_rndr_sw_t grrndrsw = {
+ (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);
+RENDERER(ega, GRAPHICS_MODE, grrndrsw);
+RENDERER(vga, GRAPHICS_MODE, grrndrsw);
+#endif /* SC_NO_MODE_CHANGE */
+
+#ifndef SC_NO_CUTPASTE
+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
+
+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)
+{
+ (*vidsw[scp->sc->adapter]->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->cursor_base = base;
+ scp->cursor_height = height;
+#endif
+ (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
+ base, height,
+ scp->font_size, blink);
+}
+
+static void
+vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ video_adapter_t *adp;
+ int cursor_attr;
+
+ if (scp->cursor_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;
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp,
+ at%scp->xsize,
+ at/scp->xsize);
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp,
+ -1, -1);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ } else {
+ scp->status &= ~VR_CURSOR_BLINK;
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ cursor_attr = sc_vtb_geta(&scp->vtb, at);
+ scp->cursor_saveunder_char = sc_vtb_getc(&scp->scr, at);
+ scp->cursor_saveunder_attr = cursor_attr;
+ if ((cursor_attr & 0x7000) == 0x7000) {
+ cursor_attr &= 0x8f00;
+ if ((cursor_attr & 0x0700) == 0)
+ cursor_attr |= 0x0700;
+ } else {
+ cursor_attr |= 0x7000;
+ if ((cursor_attr & 0x0700) == 0x0700)
+ cursor_attr &= 0xf000;
+ }
+ if (flip)
+ cursor_attr = (cursor_attr & 0x8800)
+ | ((cursor_attr & 0x7000) >> 4)
+ | ((cursor_attr & 0x0700) << 4);
+ sc_vtb_putc(&scp->scr, at,
+ sc_vtb_getc(&scp->scr, at),
+ cursor_attr);
+ } 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
+ u_char font_buf[128];
+ u_short cursor[32];
+ 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->vtb, pos)*scp->font_size,
+ &font_buf[0], scp->font_size);
+ bcopy(scp->font + sc_vtb_getc(&scp->vtb, pos + 1)*scp->font_size,
+ &font_buf[32], scp->font_size);
+ bcopy(scp->font
+ + sc_vtb_getc(&scp->vtb, pos + scp->xsize)*scp->font_size,
+ &font_buf[64], scp->font_size);
+ bcopy(scp->font
+ + sc_vtb_getc(&scp->vtb, 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
+ (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
+ SC_MOUSE_CHAR, 4);
+
+ sc_vtb_putc(&scp->scr, pos, SC_MOUSE_CHAR, sc_vtb_geta(&scp->scr, pos));
+ /* FIXME: may be out of range! */
+ sc_vtb_putc(&scp->scr, pos + scp->xsize, SC_MOUSE_CHAR + 2,
+ sc_vtb_geta(&scp->scr, pos + scp->xsize));
+ if (x < (scp->xsize - 1)*8) {
+ sc_vtb_putc(&scp->scr, pos + 1, SC_MOUSE_CHAR + 1,
+ sc_vtb_geta(&scp->scr, pos + 1));
+ sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, SC_MOUSE_CHAR + 3,
+ sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
+ }
+#else /* 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);
+#endif /* SC_ALT_MOUSE_IMAGE */
+}
+
+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_pxlclear(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(scr_stat *scp, int color)
+{
+ vm_offset_t p;
+ int line_width;
+ int i;
+
+ (*vidsw[scp->sc->adapter]->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);
+ bzero_io((void *)(p + line_width*(scp->yoff + scp->ysize)
+ *scp->font_size),
+ line_width*(scp->ypixel
+ - (scp->yoff + scp->ysize)*scp->font_size));
+ }
+ if (scp->xoff > 0) {
+ for (i = 0; i < scp->ysize*scp->font_size; ++i) {
+ bzero_io((void *)(p + line_width
+ *(scp->yoff*scp->font_size + i)),
+ scp->xoff);
+ bzero_io((void *)(p + line_width
+ *(scp->yoff*scp->font_size + i)
+ + scp->xoff + scp->xsize),
+ scp->xpixel/8 - scp->xoff - scp->xsize);
+ }
+ }
+ 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 = scp->sc->adp->va_window
+ + scp->xoff
+ + scp->yoff*scp->font_size*line_width
+ + (from%scp->xsize)
+ + scp->font_size*line_width*(from/scp->xsize);
+
+ 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(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 = scp->sc->adp->va_window
+ + scp->xoff
+ + scp->yoff*scp->font_size*line_width
+ + (from%scp->xsize)
+ + scp->font_size*line_width*(from/scp->xsize);
+
+ 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->cursor_base = base;
+ scp->cursor_height = height;
+#endif
+}
+
+static void
+draw_pxlcursor(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 = scp->sc->adp->va_window
+ + scp->xoff
+ + scp->yoff*scp->font_size*line_width
+ + (at%scp->xsize)
+ + scp->font_size*line_width*(at/scp->xsize)
+ + (scp->font_size - scp->cursor_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->cursor_base - 1]);
+ height = imin(scp->cursor_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 void
+vga_pxlcursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ if (scp->cursor_height <= 0) /* the text cursor is disabled */
+ return;
+
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ draw_pxlcursor(scp, at, on, flip);
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ draw_pxlcursor(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(scr_stat *scp, int at, int flip)
+{
+ static int blinkrate = 0;
+
+ if (!(scp->status & VR_CURSOR_BLINK))
+ return;
+ if (!(++blinkrate & 4))
+ return;
+ blinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ draw_pxlcursor(scp, at, scp->status & VR_CURSOR_ON, flip);
+}
+
+#ifndef SC_NO_CUTPASTE
+
+static void
+draw_pxlmouse(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 - 16) {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = ~(mouse_and_mask[j] >> xoff);
+#ifdef __i386__
+ *(u_char *)p &= m >> 8;
+ *(u_char *)(p + 1) &= m;
+#elif defined(__alpha__)
+ 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);
+#ifdef __i386__
+ *(u_char *)p &= m;
+#elif defined(__alpha__)
+ 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 - 16) {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = mouse_or_mask[j] >> xoff;
+#ifdef __i386__
+ *(u_char *)p &= m >> 8;
+ *(u_char *)(p + 1) &= m;
+#elif defined(__alpha__)
+ 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;
+#ifdef __i386__
+ *(u_char *)p &= m;
+#elif defined(__alpha__)
+ 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(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(scr_stat *scp, int x, int y, int on)
+{
+ if (on)
+ draw_pxlmouse(scp, x, y);
+ else
+ remove_pxlmouse(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)
+{
+ (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
+}
+
+#endif
+
+#endif /* NSC > 0 && NVGA > 0 */
diff --git a/sys/dev/syscons/schistory.c b/sys/dev/syscons/schistory.c
new file mode 100644
index 0000000..aa7de06
--- /dev/null
+++ b/sys/dev/syscons/schistory.c
@@ -0,0 +1,307 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include "sc.h"
+#include "opt_syscons.h"
+
+#if NSC > 0
+
+#ifndef SC_NO_HISTORY
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#include <machine/console.h>
+
+#include <dev/syscons/syscons.h>
+
+#if !defined(SC_MAX_HISTORY_SIZE)
+#define SC_MAX_HISTORY_SIZE (1000 * MAXCONS * NSC)
+#endif
+
+#if !defined(SC_HISTORY_SIZE)
+#define SC_HISTORY_SIZE (ROW * 4)
+#endif
+
+#if (SC_HISTORY_SIZE * MAXCONS * NSC) > SC_MAX_HISTORY_SIZE
+#undef SC_MAX_HISTORY_SIZE
+#define SC_MAX_HISTORY_SIZE (SC_HISTORY_SIZE * MAXCONS * NSC)
+#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;
+ sc_vtb_init(history, VTB_RINGBUFFER, scp->xsize, lines,
+ NULL, wait);
+ sc_vtb_clear(history, scp->sc->scr_map[0x20],
+ scp->term.cur_color);
+ 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, int flag,
+ struct proc *p)
+{
+ scr_stat *scp;
+ int error;
+
+ switch (cmd) {
+
+ case CONS_HISTORY: /* set history size */
+ scp = SC_STAT(tp->t_dev);
+ 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;
+ }
+
+ return ENOIOCTL;
+}
+
+#endif /* SC_NO_HISTORY */
+
+#endif /* NSC */
diff --git a/sys/dev/syscons/scmouse.c b/sys/dev/syscons/scmouse.c
new file mode 100644
index 0000000..ecaa329
--- /dev/null
+++ b/sys/dev/syscons/scmouse.c
@@ -0,0 +1,1071 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include "sc.h"
+#include "opt_syscons.h"
+
+#if NSC > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/signalvar.h>
+#include <sys/proc.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#include <machine/console.h>
+#include <machine/mouse.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;
+
+/* local variables */
+#ifndef SC_NO_SYSMOUSE
+static int mouse_level; /* sysmouse protocol level */
+static mousestatus_t mouse_status = { 0, 0, 0, 0, 0, 0 };
+static int cut_buffer_size;
+static u_char *cut_buffer;
+#endif /* SC_NO_SYSMOUE */
+
+/* local functions */
+#ifndef SC_NO_SYSMOUSE
+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);
+static void mouse_paste(scr_stat *scp);
+#endif /* SC_NO_CUTPASTE */
+#endif /* SC_NO_SYSMOUE */
+
+#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 */
+
+#ifndef SC_NO_SYSMOUSE
+
+/* modify the sysmouse software level */
+void
+sc_mouse_set_level(int level)
+{
+ mouse_level = level;
+}
+
+/* move mouse */
+void
+sc_mouse_move(scr_stat *scp, int x, int y)
+{
+ int s;
+
+ s = spltty();
+ scp->mouse_xpos = x;
+ scp->mouse_ypos = y;
+ scp->mouse_pos = scp->mouse_oldpos =
+ (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff;
+ splx(s);
+}
+
+/* adjust mouse position */
+static void
+set_mouse_pos(scr_stat *scp)
+{
+ static int last_xpos = -1, last_ypos = -1;
+
+ if (scp->mouse_xpos < scp->xoff*8)
+ scp->mouse_xpos = scp->xoff*8;
+ 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)*8 - 1)
+ scp->mouse_xpos = (scp->xsize + scp->xoff)*8 - 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 != last_xpos || scp->mouse_ypos != last_ypos) {
+ scp->status |= MOUSE_MOVED;
+ scp->mouse_pos =
+ (scp->mouse_ypos/scp->font_size - scp->yoff)*scp->xsize
+ + scp->mouse_xpos/8 - 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;
+
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->draw_mouse)(scp, scp->mouse_xpos, scp->mouse_ypos, TRUE);
+ scp->mouse_oldpos = scp->mouse_pos;
+ --scp->sc->videoio_in_progress;
+}
+
+void
+sc_remove_mouse_image(scr_stat *scp)
+{
+ int size;
+ int i;
+
+ if (ISGRAPHSC(scp))
+ return;
+
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->draw_mouse)(scp,
+ (scp->mouse_oldpos%scp->xsize + scp->xoff)*8,
+ (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->sc->videoio_in_progress;
+}
+
+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) == ' ')
+
+/* 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;
+}
+
+/* copy marked region to the cut buffer */
+static void
+mouse_cut(scr_stat *scp)
+{
+ int start;
+ int end;
+ int from;
+ int to;
+ int blank;
+ 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;
+ }
+ for (p = from, i = blank = 0; p <= to; ++p) {
+ cut_buffer[i] = sc_vtb_getc(&scp->vtb, p);
+ /* remember the position of the last non-space char */
+ if (!IS_SPACE_CHAR(cut_buffer[i++]))
+ blank = i; /* the first space after the last non-space */
+ /* trim trailing blank when crossing lines */
+ if ((p % scp->xsize) == (scp->xsize - 1)) {
+ cut_buffer[blank] = '\r';
+ i = blank + 1;
+ }
+ }
+ cut_buffer[i] = '\0';
+
+ /* scan towards the end of the last line */
+ --p;
+ 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;
+ cut_buffer[blank++] = '\r';
+ cut_buffer[blank] = '\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 = start;
+ scp->mouse_cut_end = end;
+ mark_for_update(scp, from);
+ mark_for_update(scp, to);
+ splx(s);
+}
+
+/* a mouse button is pressed, start cut operation */
+static void
+mouse_cut_start(scr_stat *scp)
+{
+ int i;
+ int j;
+ int s;
+
+ if (scp->status & MOUSE_VISIBLE) {
+ i = scp->mouse_cut_start;
+ j = scp->mouse_cut_end;
+ sc_remove_all_cutmarkings(scp->sc);
+ if (scp->mouse_pos == i && i == j) {
+ cut_buffer[0] = '\0';
+ } 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';
+ cut_buffer[1] = '\0';
+ scp->status |= MOUSE_CUTTING;
+ } 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 s;
+ int i;
+ int j;
+
+ /*
+ * 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.
+ */
+ if (scp->status & MOUSE_VISIBLE) {
+ /* remove the current cut mark */
+ 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);
+ }
+ scp->mouse_cut_start = scp->xsize*scp->ysize;
+ scp->mouse_cut_end = -1;
+ splx(s);
+
+ sol = (scp->mouse_pos / scp->xsize) * scp->xsize;
+ eol = sol + scp->xsize;
+ c = sc_vtb_getc(&scp->vtb, scp->mouse_pos);
+ if (IS_SPACE_CHAR(c)) {
+ /* blank space */
+ for (j = scp->mouse_pos; j >= sol; --j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (!IS_SPACE_CHAR(c))
+ break;
+ }
+ start = ++j;
+ for (j = scp->mouse_pos; j < eol; ++j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (!IS_SPACE_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_SPACE_CHAR(c))
+ break;
+ }
+ start = ++j;
+ for (j = scp->mouse_pos; j < eol; ++j) {
+ c = sc_vtb_getc(&scp->vtb, j);
+ if (IS_SPACE_CHAR(c))
+ break;
+ }
+ end = j - 1;
+ }
+
+ /* copy the found word */
+ for (i = 0, j = start; j <= end; ++j)
+ cut_buffer[i++] = sc_vtb_getc(&scp->vtb, j);
+ cut_buffer[i] = '\0';
+ scp->status |= MOUSE_CUTTING;
+
+ /* mark the region */
+ s = spltty();
+ scp->mouse_cut_start = start;
+ scp->mouse_cut_end = end;
+ mark_for_update(scp, start);
+ mark_for_update(scp, end);
+ splx(s);
+ }
+}
+
+/* copy a line under the mouse pointer */
+static void
+mouse_cut_line(scr_stat *scp)
+{
+ int s;
+ int i;
+ int j;
+
+ if (scp->status & MOUSE_VISIBLE) {
+ /* remove the current cut mark */
+ 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 entire line */
+ scp->mouse_cut_start =
+ (scp->mouse_pos / scp->xsize) * scp->xsize;
+ scp->mouse_cut_end = scp->mouse_cut_start + scp->xsize - 1;
+ mark_for_update(scp, scp->mouse_cut_start);
+ mark_for_update(scp, scp->mouse_cut_end);
+ splx(s);
+
+ /* copy the line into the cut buffer */
+ for (i = 0, j = scp->mouse_cut_start; j <= scp->mouse_cut_end; ++j)
+ cut_buffer[i++] = sc_vtb_getc(&scp->vtb, j);
+ cut_buffer[i++] = '\r';
+ cut_buffer[i] = '\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 */
+static void
+mouse_paste(scr_stat *scp)
+{
+ if (scp->status & MOUSE_VISIBLE)
+ 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, int flag,
+ struct proc *p)
+{
+
+ scr_stat *scp;
+ int s;
+ int i;
+
+ /* scp == NULL, if tp == sc_get_mouse_tty() (/dev/sysmouse) */
+ scp = SC_STAT(tp->t_dev);
+
+ switch (cmd) {
+
+ case CONS_MOUSECTL: /* control mouse arrow */
+ case OLD_CONS_MOUSECTL:
+ {
+ /* 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,
+ };
+ mouse_info_t *mouse = (mouse_info_t*)data;
+ mouse_info_t buf;
+ scr_stat *cur_scp;
+ struct tty *mtty;
+ int f;
+
+ if (scp == NULL)
+ return ENOTTY;
+
+ 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];
+ break;
+ 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 = p;
+ scp->mouse_pid = p->p_pid;
+ }
+ else {
+ scp->mouse_signal = 0;
+ scp->mouse_proc = NULL;
+ scp->mouse_pid = 0;
+ }
+ return 0;
+
+ case MOUSE_SHOW:
+ if (!ISMOUSEAVAIL(scp->sc->adp->va_flags))
+ return EINVAL;
+ s = spltty();
+ if (!(scp->sc->flags & SC_MOUSE_ENABLED)) {
+ scp->sc->flags |= SC_MOUSE_ENABLED;
+ if (!ISGRAPHSC(cur_scp)) {
+ cur_scp->status |= MOUSE_VISIBLE;
+ mark_all(cur_scp);
+ }
+ splx(s);
+ return 0;
+ } else {
+ splx(s);
+ return EINVAL;
+ }
+ break;
+
+ 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;
+ } else {
+ splx(s);
+ return EINVAL;
+ }
+ break;
+
+ 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);
+
+ mouse_status.dx += mouse->u.data.x;
+ mouse_status.dy += mouse->u.data.y;
+ mouse_status.dz += mouse->u.data.z;
+ if (mouse->operation == MOUSE_ACTION)
+ mouse_status.button = mouse->u.data.buttons;
+ mouse_status.flags |=
+ ((mouse->u.data.x || mouse->u.data.y || mouse->u.data.z) ?
+ MOUSE_POSCHANGED : 0)
+ | (mouse_status.obutton ^ mouse_status.button);
+ if (mouse_status.flags == 0)
+ return 0;
+
+ mtty = sc_get_mouse_tty();
+ if (mtty->t_state & TS_ISOPEN) {
+ u_char buf[MOUSE_SYS_PACKETSIZE];
+
+ /* the first five bytes are compatible with MouseSystems' */
+ buf[0] = MOUSE_MSC_SYNC
+ | butmap[mouse_status.button & MOUSE_STDBUTTONS];
+ i = imax(imin(mouse->u.data.x, 255), -256);
+ buf[1] = i >> 1;
+ buf[3] = i - buf[1];
+ i = -imax(imin(mouse->u.data.y, 255), -256);
+ buf[2] = i >> 1;
+ buf[4] = i - buf[2];
+ for (i = 0; i < MOUSE_MSC_PACKETSIZE; i++)
+ (*linesw[mtty->t_line].l_rint)(buf[i], mtty);
+ if (mouse_level >= 1) { /* extended part */
+ i = imax(imin(mouse->u.data.z, 127), -128);
+ buf[5] = (i >> 1) & 0x7f;
+ buf[6] = (i - (i >> 1)) & 0x7f;
+ /* buttons 4-10 */
+ buf[7] = (~mouse_status.button >> 3) & 0x7f;
+ for (i = MOUSE_MSC_PACKETSIZE;
+ i < MOUSE_SYS_PACKETSIZE; i++)
+ (*linesw[mtty->t_line].l_rint)(buf[i], mtty);
+ }
+ }
+
+ /*
+ * 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();
+ }
+
+#ifndef SC_NO_CUTPASTE
+ if (!ISGRAPHSC(cur_scp) && (cur_scp->sc->flags & SC_MOUSE_ENABLED))
+ cur_scp->status |= MOUSE_VISIBLE;
+#endif /* SC_NO_CUTPASTE */
+
+ if (cur_scp->mouse_signal) {
+ /* has controlling process died? */
+ if (cur_scp->mouse_proc &&
+ (cur_scp->mouse_proc != pfind(cur_scp->mouse_pid))){
+ cur_scp->mouse_signal = 0;
+ cur_scp->mouse_proc = NULL;
+ cur_scp->mouse_pid = 0;
+ } else {
+ psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
+ break;
+ }
+ }
+
+ if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
+ break;
+
+#ifndef SC_NO_CUTPASTE
+ 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)
+ 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;
+ mouse_status.button |= mouse->u.event.id;
+ } else {
+ cur_scp->mouse_buttons &= ~mouse->u.event.id;
+ mouse_status.button &= ~mouse->u.event.id;
+ }
+ mouse_status.flags |= mouse_status.obutton ^ mouse_status.button;
+ if (mouse_status.flags == 0)
+ return 0;
+
+ mtty = sc_get_mouse_tty();
+ if (mtty->t_state & TS_ISOPEN) {
+ u_char buf[MOUSE_SYS_PACKETSIZE];
+
+ buf[0] = MOUSE_MSC_SYNC
+ | butmap[mouse_status.button & MOUSE_STDBUTTONS];
+ buf[7] = (~mouse_status.button >> 3) & 0x7f;
+ buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0;
+ for (i = 0;
+ i < ((mouse_level >= 1) ? MOUSE_SYS_PACKETSIZE
+ : MOUSE_MSC_PACKETSIZE); i++)
+ (*linesw[mtty->t_line].l_rint)(buf[i], mtty);
+ }
+
+ /* if a button is held down, stop the screen saver */
+ if (mouse->u.event.value > 0)
+ sc_touch_scrn_saver();
+
+#ifndef SC_NO_CUTPASTE
+ if (!ISGRAPHSC(cur_scp) && (cur_scp->sc->flags & SC_MOUSE_ENABLED))
+ cur_scp->status |= MOUSE_VISIBLE;
+#endif /* SC_NO_CUTPASTE */
+
+ if (cur_scp->mouse_signal) {
+ if (cur_scp->mouse_proc &&
+ (cur_scp->mouse_proc != pfind(cur_scp->mouse_pid))){
+ cur_scp->mouse_signal = 0;
+ cur_scp->mouse_proc = NULL;
+ cur_scp->mouse_pid = 0;
+ } else {
+ psignal(cur_scp->mouse_proc, cur_scp->mouse_signal);
+ break;
+ }
+ }
+
+ if (ISGRAPHSC(cur_scp) || (cut_buffer == NULL))
+ break;
+
+#ifndef SC_NO_CUTPASTE
+ 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:
+ 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;
+
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+ }
+
+ /* MOUSE_XXX: /dev/sysmouse ioctls */
+ case MOUSE_GETHWINFO: /* get device information */
+ {
+ mousehw_t *hw = (mousehw_t *)data;
+
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ 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 */
+ {
+ mousemode_t *mode = (mousemode_t *)data;
+
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ mode->level = mouse_level;
+ switch (mode->level) {
+ case 0:
+ /* at this level, sysmouse emulates 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:
+ /* at this level, sysmouse uses its own 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 */
+ {
+ mousemode_t *mode = (mousemode_t *)data;
+
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ if ((mode->level < 0) || (mode->level > 1))
+ return EINVAL;
+ sc_mouse_set_level(mode->level);
+ return 0;
+ }
+
+ case MOUSE_GETLEVEL: /* get operation level */
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ *(int *)data = mouse_level;
+ return 0;
+
+ case MOUSE_SETLEVEL: /* set operation level */
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ if ((*(int *)data < 0) || (*(int *)data > 1))
+ return EINVAL;
+ sc_mouse_set_level(*(int *)data);
+ return 0;
+
+ case MOUSE_GETSTATUS: /* get accumulated mouse events */
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ s = spltty();
+ *(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;
+ splx(s);
+ return 0;
+
+#if notyet
+ case MOUSE_GETVARS: /* get internal mouse variables */
+ case MOUSE_SETVARS: /* set internal mouse variables */
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ return ENODEV;
+#endif
+
+ case MOUSE_READSTATE: /* read status from the device */
+ case MOUSE_READDATA: /* read data from the device */
+ if (tp != sc_get_mouse_tty())
+ return ENOTTY;
+ return ENODEV;
+ }
+
+ return ENOIOCTL;
+}
+
+#endif /* SC_NO_SYSMOUSE */
+
+#endif /* NSC */
diff --git a/sys/dev/syscons/scvesactl.c b/sys/dev/syscons/scvesactl.c
new file mode 100644
index 0000000..9749cc2
--- /dev/null
+++ b/sys/dev/syscons/scvesactl.c
@@ -0,0 +1,141 @@
+/*-
+ * Copyright (c) 1998 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 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 "sc.h"
+#include "vga.h"
+#include "opt_syscons.h"
+#include "opt_vga.h"
+#include "opt_vesa.h"
+
+#ifdef VGA_NO_MODE_CHANGE
+#undef VESA
+#endif
+
+#if (NSC > 0 && NVGA > 0 && defined(VESA)) || defined(KLD_MODULE)
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+
+#include <machine/console.h>
+#include <machine/pc/vesa.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/syscons/syscons.h>
+
+static d_ioctl_t *prev_user_ioctl;
+
+static int
+vesa_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ scr_stat *scp;
+ struct tty *tp;
+ int mode;
+
+ tp = dev->si_tty;
+ if (!tp)
+ return ENXIO;
+ scp = SC_STAT(tp->t_dev);
+
+ 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);
+
+ /* 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);
+
+ /* 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);
+ }
+
+ if (prev_user_ioctl)
+ return (*prev_user_ioctl)(dev, cmd, data, flag, p);
+ 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 /* (NSC > 0 && NVGA > 0 && VESA) || KLD_MODULE */
diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c
new file mode 100644
index 0000000..8a1cdaa
--- /dev/null
+++ b/sys/dev/syscons/scvgarndr.c
@@ -0,0 +1,829 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include "sc.h"
+#include "vga.h"
+#include "opt_syscons.h"
+#include "opt_vga.h"
+
+#if NSC > 0 && NVGA > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <machine/console.h>
+#include <machine/md_var.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/vgareg.h>
+#include <dev/syscons/syscons.h>
+
+#include <isa/isareg.h>
+
+#ifndef SC_MOUSE_CHAR
+#define SC_MOUSE_CHAR (0xd0)
+#endif
+
+#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_clear_t vga_pxlclear;
+static vr_draw_border_t vga_pxlborder;
+static vr_draw_t vga_egadraw;
+static vr_draw_t vga_vgadraw;
+static vr_set_cursor_t vga_pxlcursor_shape;
+static vr_draw_cursor_t vga_pxlcursor;
+static vr_blink_cursor_t vga_pxlblink;
+#ifndef SC_NO_CUTPASTE
+static vr_draw_mouse_t vga_pxlmouse;
+#else
+#define vga_pxlmouse (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 = {
+ 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);
+RENDERER(cga, 0, txtrndrsw);
+RENDERER(ega, 0, txtrndrsw);
+RENDERER(vga, 0, txtrndrsw);
+
+#ifdef SC_PIXEL_MODE
+static sc_rndr_sw_t egarndrsw = {
+ vga_pxlclear,
+ vga_pxlborder,
+ vga_egadraw,
+ vga_pxlcursor_shape,
+ vga_pxlcursor,
+ vga_pxlblink,
+ (vr_set_mouse_t *)vga_nop,
+ vga_pxlmouse,
+};
+RENDERER(ega, PIXEL_MODE, egarndrsw);
+
+static sc_rndr_sw_t vgarndrsw = {
+ vga_pxlclear,
+ vga_pxlborder,
+ vga_vgadraw,
+ vga_pxlcursor_shape,
+ vga_pxlcursor,
+ vga_pxlblink,
+ (vr_set_mouse_t *)vga_nop,
+ vga_pxlmouse,
+};
+RENDERER(vga, PIXEL_MODE, vgarndrsw);
+#endif /* SC_PIXEL_MODE */
+
+#ifndef SC_NO_MODE_CHANGE
+static sc_rndr_sw_t grrndrsw = {
+ (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);
+RENDERER(ega, GRAPHICS_MODE, grrndrsw);
+RENDERER(vga, GRAPHICS_MODE, grrndrsw);
+#endif /* SC_NO_MODE_CHANGE */
+
+#ifndef SC_NO_CUTPASTE
+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
+
+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)
+{
+ (*vidsw[scp->sc->adapter]->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->cursor_base = base;
+ scp->cursor_height = height;
+#endif
+ (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp,
+ base, height,
+ scp->font_size, blink);
+}
+
+static void
+vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ video_adapter_t *adp;
+ int cursor_attr;
+
+ if (scp->cursor_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;
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp,
+ at%scp->xsize,
+ at/scp->xsize);
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp,
+ -1, -1);
+ scp->status &= ~VR_CURSOR_ON;
+ }
+ } else {
+ scp->status &= ~VR_CURSOR_BLINK;
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ cursor_attr = sc_vtb_geta(&scp->vtb, at);
+ scp->cursor_saveunder_char = sc_vtb_getc(&scp->scr, at);
+ scp->cursor_saveunder_attr = cursor_attr;
+ if ((cursor_attr & 0x7000) == 0x7000) {
+ cursor_attr &= 0x8f00;
+ if ((cursor_attr & 0x0700) == 0)
+ cursor_attr |= 0x0700;
+ } else {
+ cursor_attr |= 0x7000;
+ if ((cursor_attr & 0x0700) == 0x0700)
+ cursor_attr &= 0xf000;
+ }
+ if (flip)
+ cursor_attr = (cursor_attr & 0x8800)
+ | ((cursor_attr & 0x7000) >> 4)
+ | ((cursor_attr & 0x0700) << 4);
+ sc_vtb_putc(&scp->scr, at,
+ sc_vtb_getc(&scp->scr, at),
+ cursor_attr);
+ } 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
+ u_char font_buf[128];
+ u_short cursor[32];
+ 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->vtb, pos)*scp->font_size,
+ &font_buf[0], scp->font_size);
+ bcopy(scp->font + sc_vtb_getc(&scp->vtb, pos + 1)*scp->font_size,
+ &font_buf[32], scp->font_size);
+ bcopy(scp->font
+ + sc_vtb_getc(&scp->vtb, pos + scp->xsize)*scp->font_size,
+ &font_buf[64], scp->font_size);
+ bcopy(scp->font
+ + sc_vtb_getc(&scp->vtb, 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
+ (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, font_buf,
+ SC_MOUSE_CHAR, 4);
+
+ sc_vtb_putc(&scp->scr, pos, SC_MOUSE_CHAR, sc_vtb_geta(&scp->scr, pos));
+ /* FIXME: may be out of range! */
+ sc_vtb_putc(&scp->scr, pos + scp->xsize, SC_MOUSE_CHAR + 2,
+ sc_vtb_geta(&scp->scr, pos + scp->xsize));
+ if (x < (scp->xsize - 1)*8) {
+ sc_vtb_putc(&scp->scr, pos + 1, SC_MOUSE_CHAR + 1,
+ sc_vtb_geta(&scp->scr, pos + 1));
+ sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, SC_MOUSE_CHAR + 3,
+ sc_vtb_geta(&scp->scr, pos + scp->xsize + 1));
+ }
+#else /* 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);
+#endif /* SC_ALT_MOUSE_IMAGE */
+}
+
+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_pxlclear(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(scr_stat *scp, int color)
+{
+ vm_offset_t p;
+ int line_width;
+ int i;
+
+ (*vidsw[scp->sc->adapter]->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);
+ bzero_io((void *)(p + line_width*(scp->yoff + scp->ysize)
+ *scp->font_size),
+ line_width*(scp->ypixel
+ - (scp->yoff + scp->ysize)*scp->font_size));
+ }
+ if (scp->xoff > 0) {
+ for (i = 0; i < scp->ysize*scp->font_size; ++i) {
+ bzero_io((void *)(p + line_width
+ *(scp->yoff*scp->font_size + i)),
+ scp->xoff);
+ bzero_io((void *)(p + line_width
+ *(scp->yoff*scp->font_size + i)
+ + scp->xoff + scp->xsize),
+ scp->xpixel/8 - scp->xoff - scp->xsize);
+ }
+ }
+ 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 = scp->sc->adp->va_window
+ + scp->xoff
+ + scp->yoff*scp->font_size*line_width
+ + (from%scp->xsize)
+ + scp->font_size*line_width*(from/scp->xsize);
+
+ 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(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 = scp->sc->adp->va_window
+ + scp->xoff
+ + scp->yoff*scp->font_size*line_width
+ + (from%scp->xsize)
+ + scp->font_size*line_width*(from/scp->xsize);
+
+ 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->cursor_base = base;
+ scp->cursor_height = height;
+#endif
+}
+
+static void
+draw_pxlcursor(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 = scp->sc->adp->va_window
+ + scp->xoff
+ + scp->yoff*scp->font_size*line_width
+ + (at%scp->xsize)
+ + scp->font_size*line_width*(at/scp->xsize)
+ + (scp->font_size - scp->cursor_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->cursor_base - 1]);
+ height = imin(scp->cursor_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 void
+vga_pxlcursor(scr_stat *scp, int at, int blink, int on, int flip)
+{
+ if (scp->cursor_height <= 0) /* the text cursor is disabled */
+ return;
+
+ if (on) {
+ scp->status |= VR_CURSOR_ON;
+ draw_pxlcursor(scp, at, on, flip);
+ } else {
+ if (scp->status & VR_CURSOR_ON)
+ draw_pxlcursor(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(scr_stat *scp, int at, int flip)
+{
+ static int blinkrate = 0;
+
+ if (!(scp->status & VR_CURSOR_BLINK))
+ return;
+ if (!(++blinkrate & 4))
+ return;
+ blinkrate = 0;
+ scp->status ^= VR_CURSOR_ON;
+ draw_pxlcursor(scp, at, scp->status & VR_CURSOR_ON, flip);
+}
+
+#ifndef SC_NO_CUTPASTE
+
+static void
+draw_pxlmouse(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 - 16) {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = ~(mouse_and_mask[j] >> xoff);
+#ifdef __i386__
+ *(u_char *)p &= m >> 8;
+ *(u_char *)(p + 1) &= m;
+#elif defined(__alpha__)
+ 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);
+#ifdef __i386__
+ *(u_char *)p &= m;
+#elif defined(__alpha__)
+ 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 - 16) {
+ for (i = y, j = 0; i < ymax; ++i, ++j) {
+ m = mouse_or_mask[j] >> xoff;
+#ifdef __i386__
+ *(u_char *)p &= m >> 8;
+ *(u_char *)(p + 1) &= m;
+#elif defined(__alpha__)
+ 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;
+#ifdef __i386__
+ *(u_char *)p &= m;
+#elif defined(__alpha__)
+ 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(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(scr_stat *scp, int x, int y, int on)
+{
+ if (on)
+ draw_pxlmouse(scp, x, y);
+ else
+ remove_pxlmouse(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)
+{
+ (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color);
+}
+
+#endif
+
+#endif /* NSC > 0 && NVGA > 0 */
diff --git a/sys/dev/syscons/scvidctl.c b/sys/dev/syscons/scvidctl.c
new file mode 100644
index 0000000..0923a7b
--- /dev/null
+++ b/sys/dev/syscons/scvidctl.c
@@ -0,0 +1,789 @@
+/*-
+ * Copyright (c) 1998 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 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 "sc.h"
+#include "opt_syscons.h"
+
+#if NSC > 0
+
+#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 <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <machine/console.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/syscons/syscons.h>
+
+/* 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)
+{
+ video_info_t info;
+ sc_rndr_sw_t *rndr;
+ u_char *font;
+ int prev_ysize;
+ int error;
+ int s;
+
+ if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
+ return ENODEV;
+
+ /* 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))
+ 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;
+ }
+
+ rndr = sc_render_match(scp, scp->sc->adp, 0);
+ if (rndr == 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;
+ scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
+ 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;
+
+ /* allocate buffers */
+ sc_alloc_scr_buffer(scp, TRUE, TRUE);
+#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
+ scp->rndr = rndr;
+ 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;
+ pgsignal(tp->t_pgrp, SIGWINCH, 1);
+ }
+
+ 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;
+ sc_rndr_sw_t *rndr;
+ int error;
+ int s;
+
+ if ((*vidsw[scp->sc->adapter]->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;
+ }
+
+ rndr = sc_render_match(scp, scp->sc->adp, GRAPHICS_MODE);
+ if (rndr == NULL) {
+ splx(s);
+ return ENODEV;
+ }
+
+ /* set up scp */
+ scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE);
+ scp->status &= ~PIXEL_MODE;
+ 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 = FONT_NONE;
+#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
+ scp->rndr = rndr;
+ 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;
+ pgsignal(tp->t_pgrp, SIGWINCH, 1);
+ }
+
+ return 0;
+#endif /* SC_NO_MODE_CHANGE */
+}
+
+int
+sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
+ int fontsize)
+{
+#ifndef SC_PIXEL_MODE
+ return ENODEV;
+#else
+ video_info_t info;
+ sc_rndr_sw_t *rndr;
+ u_char *font;
+ int prev_ysize;
+ int error;
+ int s;
+
+ if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
+ return ENODEV; /* this shouldn't happen */
+
+ /* adjust argument values */
+ if ((fontsize <= 0) || (fontsize == FONT_NONE))
+ 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;
+
+ /* only 16 color, 4 plane modes are supported XXX */
+ if ((info.vi_depth != 4) || (info.vi_planes != 4))
+ return ENODEV;
+
+ /*
+ * set_pixel_mode() currently does not support video modes whose
+ * memory size is larger than 64K. Because such modes require
+ * bank switching to access the entire screen. XXX
+ */
+ if (info.vi_width*info.vi_height/8 > info.vi_window_size)
+ return ENODEV;
+
+ /* stop screen saver, etc */
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+
+ rndr = sc_render_match(scp, scp->sc->adp, PIXEL_MODE);
+ if (rndr == 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;
+ scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
+ scp->status &= ~GRAPHICS_MODE;
+ 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;
+
+ /* allocate buffers */
+ sc_alloc_scr_buffer(scp, TRUE, TRUE);
+#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
+ scp->rndr = rndr;
+ splx(s);
+
+ if (scp == scp->sc->cur_scp) {
+ 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;
+ pgsignal(tp->t_pgrp, SIGWINCH, 1);
+ }
+
+ return 0;
+#endif /* SC_PIXEL_MODE */
+}
+
+sc_rndr_sw_t
+*sc_render_match(scr_stat *scp, video_adapter_t *adp, int mode)
+{
+ const sc_renderer_t **list;
+ const sc_renderer_t *p;
+
+ list = (const sc_renderer_t **)scrndr_set.ls_items;
+ while ((p = *list++) != NULL) {
+ if ((strcmp(p->name, adp->va_name) == 0)
+ && (mode == p->mode)) {
+ scp->status &= ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
+ return p->rndrsw;
+ }
+ }
+
+ return NULL;
+}
+
+#define fb_ioctl(a, c, d) \
+ (((a) == NULL) ? ENODEV : \
+ (*vidsw[(a)->va_index]->ioctl)((a), (c), (caddr_t)(d)))
+
+int
+sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ scr_stat *scp;
+ video_adapter_t *adp;
+ video_info_t info;
+ video_adapter_info_t adp_info;
+ int error;
+ int s;
+
+ scp = SC_STAT(tp->t_dev);
+ 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);
+#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);
+
+ 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);
+
+#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:
+ /* FALL THROUGH */
+
+ /* 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);
+
+ /* 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:
+ if (!(adp->va_flags & V_ADP_MODECHANGE))
+ return ENODEV;
+ return sc_set_graphics_mode(scp, tp, cmd & 0xff);
+#endif /* SC_NO_MODE_CHANGE */
+
+ 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)
+ copy_font(scp, LOAD, 8, scp->sc->font_8);
+ if (scp->sc->fonts_loaded & FONT_14)
+ copy_font(scp, LOAD, 14, scp->sc->font_14);
+ if (scp->sc->fonts_loaded & FONT_16)
+ copy_font(scp, LOAD, 16, scp->sc->font_16);
+ }
+#endif /* SC_NO_FONT_LOADING */
+#endif
+
+#ifndef SC_NO_PALETTE_LOADING
+ load_palette(adp, scp->sc->palette);
+#endif
+
+#ifndef PC98
+ /* move hardware cursor out of the way */
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
+#endif
+
+ /* FALL THROUGH */
+
+ 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;
+ 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);
+ s = spltty();
+ if ((error = sc_clean_up(scp))) {
+ splx(s);
+ return error;
+ }
+ scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
+ splx(s);
+ if (scp == scp->sc->cur_scp) {
+ set_mode(scp);
+#ifndef SC_NO_PALETTE_LOADING
+ 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;
+ 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]);
+#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;
+
+ case KDSBORDER: /* set border color of this (virtual) console */
+ scp->border = *data;
+ if (scp == scp->sc->cur_scp)
+ set_border(scp, scp->border);
+ return 0;
+ }
+
+ return ENOIOCTL;
+}
+
+#endif /* NSC > 0 */
diff --git a/sys/dev/syscons/scvtb.c b/sys/dev/syscons/scvtb.c
new file mode 100644
index 0000000..eebeb23
--- /dev/null
+++ b/sys/dev/syscons/scvtb.c
@@ -0,0 +1,301 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include "sc.h"
+#include "opt_syscons.h"
+
+#if NSC > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#include <machine/console.h>
+#include <machine/md_var.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 = NULL;
+ 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 != NULL)
+ bzero((void *)sc_vtb_pointer(vtb, 0),
+ cols*rows*sizeof(u_int16_t));
+ } else {
+ vtb->vtb_buffer = (vm_offset_t)buf;
+ }
+ vtb->vtb_flags |= VTB_VALID;
+ break;
+ case VTB_FRAMEBUFFER:
+ vtb->vtb_buffer = (vm_offset_t)buf;
+ vtb->vtb_flags |= VTB_VALID;
+ break;
+ default:
+ break;
+ }
+}
+
+void
+sc_vtb_destroy(sc_vtb_t *vtb)
+{
+ vm_offset_t p;
+
+ vtb->vtb_flags = 0;
+ vtb->vtb_cols = 0;
+ vtb->vtb_rows = 0;
+ vtb->vtb_size = 0;
+ vtb->vtb_tail = 0;
+
+ p = vtb->vtb_buffer;
+ vtb->vtb_buffer = NULL;
+ switch (vtb->vtb_type) {
+ case VTB_MEMORY:
+ case VTB_RINGBUFFER:
+ if (p != NULL)
+ free((void *)p, M_DEVBUF);
+ break;
+ default:
+ break;
+ }
+ 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)
+{
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ return (readw(sc_vtb_pointer(vtb, at)) & 0x00ff);
+ else
+ return (*(u_int16_t *)sc_vtb_pointer(vtb, at) & 0x00ff);
+}
+
+int
+sc_vtb_geta(sc_vtb_t *vtb, int at)
+{
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ return (readw(sc_vtb_pointer(vtb, at)) & 0xff00);
+ else
+ return (*(u_int16_t *)sc_vtb_pointer(vtb, at) & 0xff00);
+}
+
+void
+sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a)
+{
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ writew(sc_vtb_pointer(vtb, at), a | c);
+ else
+ *(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)
+{
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ writew(p, a | c);
+ else
+ *(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)
+{
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, 0), vtb->vtb_size);
+ else
+ 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)
+{
+ /* 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 {
+ 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);
+ 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 {
+ 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;
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, at), count);
+ else
+ 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;
+ if (vtb->vtb_type == VTB_FRAMEBUFFER) {
+ bcopy_io(sc_vtb_pointer(vtb, from),
+ sc_vtb_pointer(vtb, to), count*sizeof(u_int16_t));
+ } else {
+ 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) {
+ 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 {
+ bcopy((void *)sc_vtb_pointer(vtb, at + count),
+ (void *)sc_vtb_pointer(vtb, at),
+ len*sizeof(u_int16_t));
+ }
+ }
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, at + len),
+ vtb->vtb_size - at - len);
+ else
+ 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 {
+ 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 {
+ bcopy((void *)sc_vtb_pointer(vtb, at),
+ (void *)sc_vtb_pointer(vtb, at + count),
+ (vtb->vtb_size - at - count)*sizeof(u_int16_t));
+ }
+ }
+ if (vtb->vtb_type == VTB_FRAMEBUFFER)
+ fillw_io(attr | c, sc_vtb_pointer(vtb, at), count);
+ else
+ fillw(attr | c, (void *)sc_vtb_pointer(vtb, at), count);
+}
+
+#endif /* NSC */
diff --git a/sys/dev/syscons/snake/snake_saver.c b/sys/dev/syscons/snake/snake_saver.c
new file mode 100644
index 0000000..093e564
--- /dev/null
+++ b/sys/dev/syscons/snake/snake_saver.c
@@ -0,0 +1,148 @@
+/*-
+ * 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 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) {
+#ifdef PC98
+ if (epson_machine_id == 0x20) {
+ outb(0x43f, 0x42);
+ outb(0x0c17, inb(0xc17) & ~0x08);
+ outb(0x43f, 0x40);
+ }
+#endif /* PC98 */
+ sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
+ 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 {
+#ifdef PC98
+ if (epson_machine_id == 0x20) {
+ outb(0x43f, 0x42);
+ outb(0x0c17, inb(0xc17) | 0x08);
+ outb(0x43f, 0x40);
+ }
+#endif /* PC98 */
+ 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 0000000..645e4fd
--- /dev/null
+++ b/sys/dev/syscons/star/star_saver.c
@@ -0,0 +1,135 @@
+/*-
+ * 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;
+ char pattern[] = {"...........++++*** "};
+#ifndef PC98
+ char colors[] = {FG_DARKGREY, FG_LIGHTGREY,
+ FG_WHITE, FG_LIGHTCYAN};
+#else
+ char colors[] = {FG_BLUE, FG_LIGHTGREY,
+ FG_LIGHTGREY, FG_CYAN};
+#endif /* PC98 */
+ 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) {
+#ifdef PC98
+ if (epson_machine_id == 0x20) {
+ outb(0x43f, 0x42);
+ outb(0x0c17, inb(0xc17) & ~0x08);
+ outb(0x43f, 0x40);
+ }
+#endif /* PC98 */
+ /* clear the screen and set the border color */
+ sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
+ (FG_LIGHTGREY | BG_BLACK) << 8);
+ (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
+ 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(colors)] << 8);
+ if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
+ stars[cell][0] = random() % (scp->xsize*scp->ysize);
+ stars[cell][1] = 0;
+ }
+ }
+ else {
+#ifdef PC98
+ if (epson_machine_id == 0x20) {
+ outb(0x43f, 0x42);
+ outb(0x0c17, inb(0xc17) | 0x08);
+ outb(0x43f, 0x40);
+ }
+#endif /* PC98 */
+ 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 0000000..822d42b
--- /dev/null
+++ b/sys/dev/syscons/syscons.c
@@ -0,0 +1,4046 @@
+/*-
+ * 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 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 "sc.h"
+#include "splash.h"
+#include "opt_syscons.h"
+#include "opt_ddb.h"
+#ifdef __i386__
+#include "apm.h"
+#endif
+
+#if NSC > 0
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/eventhandler.h>
+#include <sys/reboot.h>
+#include <sys/conf.h>
+#include <sys/proc.h>
+#include <sys/signalvar.h>
+#include <sys/sysctl.h>
+#include <sys/tty.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/cons.h>
+
+#include <machine/clock.h>
+#include <machine/console.h>
+#include <machine/psl.h>
+#include <machine/pc/display.h>
+#ifdef __i386__
+#include <machine/apm_bios.h>
+#include <machine/frame.h>
+#include <machine/random.h>
+#endif
+
+#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 */
+
+static default_attr user_default = {
+ SC_NORM_ATTR << 8,
+ SC_NORM_REV_ATTR << 8,
+};
+
+static default_attr kernel_default = {
+ SC_KERNEL_CONS_ATTR << 8,
+ SC_KERNEL_CONS_REV_ATTR << 8,
+};
+
+static int sc_console_unit = -1;
+static scr_stat *sc_console;
+static struct tty *sc_console_tty;
+#ifndef SC_NO_SYSMOUSE
+static struct tty *sc_mouse_tty;
+#endif
+static term_stat kernel_console;
+static default_attr *current_default;
+
+static char init_done = COLD;
+static char shutdown_in_progress = FALSE;
+static char sc_malloc = FALSE;
+
+static int saver_mode = CONS_LKM_SAVER; /* LKM/user saver */
+static int run_scrn_saver = FALSE; /* should run the saver? */
+static long scrn_blank_time = 0; /* screen saver timeout value */
+#if NSPLASH > 0
+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
+
+#if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
+#include "font.h"
+#endif
+
+ d_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, "");
+
+#define SC_MOUSE 128
+#define SC_CONSOLECTL 255
+
+#define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x))->si_tty)
+
+#define debugger FALSE
+
+#ifdef __i386__
+#ifdef DDB
+extern int in_Debugger;
+#undef debugger
+#define debugger in_Debugger
+#endif /* DDB */
+#endif /* __i386__ */
+
+/* prototypes */
+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(dev_t dev);
+static kbd_callback_func_t sckbdevent;
+static int scparam(struct tty *tp, struct termios *t);
+static void scstart(struct tty *tp);
+static void scmousestart(struct tty *tp);
+static void scinit(int unit, int flags);
+#if __i386__
+static void scterm(int unit, int flags);
+#endif
+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 int sccngetch(int flags);
+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);
+
+#if NSPLASH > 0
+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 /* !NSPLASH */
+#define scsplash_stick(stick)
+#endif /* NSPLASH */
+
+static int switch_scr(sc_softc_t *sc, u_int next_scr);
+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 void exchange_scr(sc_softc_t *sc);
+static void scan_esc(scr_stat *scp, u_char c);
+static void ansi_put(scr_stat *scp, u_char *buf, int len);
+static void draw_cursor_image(scr_stat *scp);
+static void remove_cursor_image(scr_stat *scp);
+static void update_cursor_image(scr_stat *scp);
+static void move_crsr(scr_stat *scp, int x, int y);
+static int mask2attr(struct term_stat *term);
+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 void do_bell(scr_stat *scp, int pitch, int duration);
+static timeout_t blink_screen;
+
+#define CDEV_MAJOR 12
+
+static cn_probe_t sccnprobe;
+static cn_init_t sccninit;
+static cn_getc_t sccngetc;
+static cn_checkc_t sccncheckc;
+static cn_putc_t sccnputc;
+static cn_term_t sccnterm;
+
+#if __alpha__
+void sccnattach(void);
+#endif
+
+CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc);
+
+static d_open_t scopen;
+static d_close_t scclose;
+static d_read_t scread;
+static d_ioctl_t scioctl;
+static d_mmap_t scmmap;
+
+static struct cdevsw sc_cdevsw = {
+ /* open */ scopen,
+ /* close */ scclose,
+ /* read */ scread,
+ /* write */ ttywrite,
+ /* ioctl */ scioctl,
+ /* poll */ ttypoll,
+ /* mmap */ scmmap,
+ /* strategy */ nostrategy,
+ /* name */ "sc",
+ /* maj */ CDEV_MAJOR,
+ /* dump */ nodump,
+ /* psize */ nopsize,
+ /* flags */ D_TTY,
+ /* bmaj */ -1
+};
+
+int
+sc_probe_unit(int unit, int flags)
+{
+ if (!scvidprobe(unit, flags, FALSE)) {
+ if (bootverbose)
+ printf("sc%d: no video adapter is found.\n", 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];
+}
+
+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;
+ dev_t dev;
+
+ scmeminit(NULL); /* XXX */
+
+ flags &= ~SC_KERNEL_CONSOLE;
+ if (sc_console_unit == unit)
+ flags |= SC_KERNEL_CONSOLE;
+ scinit(unit, flags);
+ sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
+ sc->config = flags;
+ scp = SC_STAT(sc->dev[0]);
+ if (sc_console == NULL) /* sc_console_unit < 0 */
+ sc_console = scp;
+
+#ifdef SC_PIXEL_MODE
+ if ((sc->config & SC_VESA800X600)
+ && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
+#if NSPLASH > 0
+ 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);
+ sc->initial_mode = M_VESA_800x600;
+#if NSPLASH > 0
+ /* 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 */
+ kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ update_kbd_state(scp, scp->status, LOCK_MASK);
+
+ printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
+ unit, adapter_name(sc->adp), sc->vtys, sc->config);
+ if (bootverbose) {
+ printf("sc%d:", unit);
+ if (sc->adapter >= 0)
+ printf(" fb%d", sc->adapter);
+ if (sc->keyboard >= 0)
+ printf(" kbd%d", sc->keyboard);
+ 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++) {
+ dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
+ UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
+ sc->dev[vc] = dev;
+ /*
+ * The first vty already has struct tty and scr_stat initialized
+ * in scinit(). The other vtys will have these structs when
+ * first opened.
+ */
+ }
+
+#ifndef SC_NO_SYSMOUSE
+ dev = make_dev(&sc_cdevsw, SC_MOUSE,
+ UID_ROOT, GID_WHEEL, 0600, "sysmouse");
+ dev->si_tty = sc_mouse_tty = ttymalloc(sc_mouse_tty);
+ /* sysmouse doesn't have scr_stat */
+#endif /* SC_NO_SYSMOUSE */
+ dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
+ UID_ROOT, GID_WHEEL, 0600, "consolectl");
+ dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
+ SC_STAT(dev) = sc_console;
+
+ 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)
+ return;
+
+ /* copy the temporary buffer to the final buffer */
+ sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
+
+#ifndef SC_NO_CUTPASTE
+ /* cut buffer is available only when the mouse pointer is used */
+ if (ISMOUSEAVAIL(sc_console->sc->adp->va_flags))
+ 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);
+
+int
+sc_resume_unit(int unit)
+{
+ /* XXX should be moved to the keyboard driver? */
+ sc_softc_t *sc;
+
+ sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
+ if (sc->kbd != NULL)
+ kbd_clear_state(sc->kbd);
+ return 0;
+}
+
+static int
+scdevtounit(dev_t dev)
+{
+ int vty = SC_VTY(dev);
+
+ if (vty == SC_CONSOLECTL)
+ return ((sc_console != NULL) ? sc_console->sc->unit : -1);
+ else if (vty == SC_MOUSE)
+ return -1;
+ else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
+ return -1;
+ else
+ return vty/MAXCONS;
+}
+
+int
+scopen(dev_t dev, int flag, int mode, struct proc *p)
+{
+ int unit = scdevtounit(dev);
+ sc_softc_t *sc;
+ struct tty *tp;
+ scr_stat *scp;
+ keyarg_t key;
+ int error;
+
+ DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
+ major(dev), minor(dev), unit, SC_VTY(dev)));
+
+ /* sc == NULL, if SC_VTY(dev) == SC_MOUSE */
+ sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
+#ifndef SC_NO_SYSMOUSE
+ if ((SC_VTY(dev) != SC_MOUSE) && (sc == NULL))
+#else
+ if (sc == NULL)
+#endif
+ return ENXIO;
+
+ tp = dev->si_tty = ttymalloc(dev->si_tty);
+ tp->t_oproc = (SC_VTY(dev) == SC_MOUSE) ? scmousestart : scstart;
+ tp->t_param = scparam;
+ tp->t_stop = nottystop;
+ tp->t_dev = dev;
+ if (!(tp->t_state & TS_ISOPEN)) {
+ ttychars(tp);
+ /* Use the current setting of the <-- key as default VERASE. */
+ /* If the Delete key is preferable, an stty is necessary */
+ if (sc != NULL) {
+ key.keynum = KEYCODE_BS;
+ kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
+ tp->t_cc[VERASE] = key.key.map[0];
+ }
+ tp->t_iflag = TTYDEF_IFLAG;
+ tp->t_oflag = TTYDEF_OFLAG;
+ tp->t_cflag = TTYDEF_CFLAG;
+ tp->t_lflag = TTYDEF_LFLAG;
+ tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
+ scparam(tp, &tp->t_termios);
+ (*linesw[tp->t_line].l_modem)(tp, 1);
+#ifndef SC_NO_SYSMOUSE
+ if (SC_VTY(dev) == SC_MOUSE)
+ sc_mouse_set_level(0); /* XXX */
+#endif
+ }
+ else
+ if (tp->t_state & TS_XCLUDE && suser(p))
+ return(EBUSY);
+
+ error = (*linesw[tp->t_line].l_open)(dev, tp);
+
+ if (SC_VTY(dev) != SC_MOUSE) {
+ /* assert(sc != NULL) */
+ scp = SC_STAT(dev);
+ if (scp == NULL) {
+ scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
+ if (ISGRAPHSC(scp))
+ sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
+ }
+ 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 error;
+}
+
+int
+scclose(dev_t dev, int flag, int mode, struct proc *p)
+{
+ struct tty *tp = dev->si_tty;
+ struct scr_stat *scp;
+ int s;
+
+ if ((SC_VTY(dev) != SC_CONSOLECTL) && (SC_VTY(dev) != SC_MOUSE)) {
+ scp = SC_STAT(tp->t_dev);
+ /* 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))
+ cons_unavail = FALSE;
+ if (scp->status & SWITCH_WAIT_REL) {
+ /* assert(scp == scp->sc->cur_scp) */
+ DPRINTF(5, ("reset WAIT_REL, "));
+ scp->status &= ~SWITCH_WAIT_REL;
+ do_switch_scr(scp->sc, s);
+ }
+ if (scp->status & SWITCH_WAIT_ACQ) {
+ /* assert(scp == scp->sc->cur_scp) */
+ DPRINTF(5, ("reset WAIT_ACQ, "));
+ scp->status &= ~SWITCH_WAIT_ACQ;
+ scp->sc->switch_in_progress = 0;
+ }
+#if not_yet_done
+ if (scp == &main_console) {
+ scp->pid = 0;
+ scp->proc = NULL;
+ scp->smode.mode = VT_AUTO;
+ }
+ else {
+ sc_vtb_destroy(&scp->vtb);
+ sc_vtb_destroy(&scp->scr);
+ sc_free_history_buffer(scp, scp->ysize);
+ 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)
+ kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ DPRINTF(5, ("done.\n"));
+ }
+ spltty();
+ (*linesw[tp->t_line].l_close)(tp, flag);
+ ttyclose(tp);
+ spl0();
+ return(0);
+}
+
+int
+scread(dev_t dev, struct uio *uio, int flag)
+{
+
+ sc_touch_scrn_saver();
+ return(ttyread(dev, uio, flag));
+}
+
+static int
+sckbdevent(keyboard_t *thiskbd, int event, void *arg)
+{
+ sc_softc_t *sc;
+ struct tty *cur_tty;
+ int c;
+ size_t len;
+ u_char *cp;
+
+ sc = (sc_softc_t *)arg;
+ /* assert(thiskbd == sc->kbd) */
+
+ switch (event) {
+ case KBDIO_KEYINPUT:
+ break;
+ case KBDIO_UNLOADING:
+ sc->kbd = NULL;
+ sc->keyboard = -1;
+ kbd_release(thiskbd, (void *)&sc->keyboard);
+ return 0;
+ default:
+ return EINVAL;
+ }
+
+ /*
+ * 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 = VIRTUAL_TTY(sc, sc->cur_scp->index);
+ /* XXX */
+ if (!(cur_tty->t_state & TS_ISOPEN))
+ if (((cur_tty = sc_console_tty) == NULL)
+ || !(cur_tty->t_state & TS_ISOPEN))
+ continue;
+
+ switch (KEYFLAGS(c)) {
+ case 0x0000: /* normal key */
+ (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
+ break;
+ case FKEY: /* function key, return string */
+ cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
+ if (cp != NULL) {
+ while (len-- > 0)
+ (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
+ }
+ break;
+ case MKEY: /* meta is active, prepend ESC */
+ (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
+ (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
+ break;
+ case BKEY: /* backtab fixed sequence (esc [ Z) */
+ (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
+ (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
+ (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
+ break;
+ }
+ }
+
+#ifndef SC_NO_CUTPASTE
+ if (sc->cur_scp->status & MOUSE_VISIBLE) {
+ sc_remove_mouse_image(sc->cur_scp);
+ sc->cur_scp->status &= ~MOUSE_VISIBLE;
+ }
+#endif /* SC_NO_CUTPASTE */
+
+ return 0;
+}
+
+static int
+scparam(struct tty *tp, struct termios *t)
+{
+ tp->t_ispeed = t->c_ispeed;
+ tp->t_ospeed = t->c_ospeed;
+ tp->t_cflag = t->c_cflag;
+ return 0;
+}
+
+int
+scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ int error;
+ int i;
+ struct tty *tp;
+ sc_softc_t *sc;
+ scr_stat *scp;
+ int s;
+
+ tp = dev->si_tty;
+
+ /* If there is a user_ioctl function call that first */
+ if (sc_user_ioctl) {
+ error = (*sc_user_ioctl)(dev, cmd, data, flag, p);
+ if (error != ENOIOCTL)
+ return error;
+ }
+
+ error = sc_vid_ioctl(tp, cmd, data, flag, p);
+ if (error != ENOIOCTL)
+ return error;
+
+#ifndef SC_NO_HISTORY
+ error = sc_hist_ioctl(tp, cmd, data, flag, p);
+ if (error != ENOIOCTL)
+ return error;
+#endif
+
+#ifndef SC_NO_SYSMOUSE
+ error = sc_mouse_ioctl(tp, cmd, data, flag, p);
+ if (error != ENOIOCTL)
+ return error;
+ if (SC_VTY(dev) == SC_MOUSE) {
+ error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
+ if (error != ENOIOCTL)
+ return error;
+ error = ttioctl(tp, cmd, data, flag);
+ if (error != ENOIOCTL)
+ return error;
+ return ENOTTY;
+ }
+#endif
+
+ scp = SC_STAT(tp->t_dev);
+ /* assert(scp != NULL) */
+ /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
+ sc = scp->sc;
+
+ switch (cmd) { /* process console hardware related ioctl's */
+
+ case GIO_ATTR: /* get current attributes */
+ *(int*)data = (scp->term.cur_attr >> 8) & 0xFF;
+ return 0;
+
+ 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 blink/noblink */
+ if (!ISGRAPHSC(sc->cur_scp))
+ remove_cursor_image(sc->cur_scp);
+ if ((*(int*)data) & 0x01)
+ sc->flags |= SC_BLINK_CURSOR;
+ else
+ sc->flags &= ~SC_BLINK_CURSOR;
+ if ((*(int*)data) & 0x02) {
+ sc->flags |= SC_CHAR_CURSOR;
+ } else
+ sc->flags &= ~SC_CHAR_CURSOR;
+ /*
+ * The cursor shape is global property; all virtual consoles
+ * are affected. Update the cursor in the current console...
+ */
+ if (!ISGRAPHSC(sc->cur_scp)) {
+ s = spltty();
+ sc_set_cursor_image(sc->cur_scp);
+ draw_cursor_image(sc->cur_scp);
+ splx(s);
+ }
+ return 0;
+
+ case CONS_BELLTYPE: /* set bell type sound/visual */
+ if ((*(int *)data) & 0x01)
+ sc->flags |= SC_VISUAL_BELL;
+ else
+ sc->flags &= ~SC_VISUAL_BELL;
+ if ((*(int *)data) & 0x02)
+ 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->mv_col = scp->xpos;
+ ptr->mv_row = scp->ypos;
+ ptr->mv_csz = scp->xsize;
+ ptr->mv_rsz = scp->ysize;
+ ptr->mv_norm.fore = (scp->term.std_color & 0x0f00)>>8;
+ ptr->mv_norm.back = (scp->term.std_color & 0xf000)>>12;
+ ptr->mv_rev.fore = (scp->term.rev_color & 0x0f00)>>8;
+ ptr->mv_rev.back = (scp->term.rev_color & 0xf000)>>12;
+ 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_USR_SAVER:
+ /* if a LKM screen saver is running, stop it first. */
+ scsplash_stick(FALSE);
+ saver_mode = *(int *)data;
+ s = spltty();
+#if NSPLASH > 0
+ if ((error = wait_scrn_saver_stop(NULL))) {
+ splx(s);
+ return error;
+ }
+#endif /* NSPLASH */
+ run_scrn_saver = TRUE;
+ 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 VT_SETMODE: /* set screen switcher mode */
+ {
+ struct vt_mode *mode;
+
+ mode = (struct vt_mode *)data;
+ DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
+ if (scp->smode.mode == VT_PROCESS) {
+ if (scp->proc == pfind(scp->pid) && scp->proc != p) {
+ DPRINTF(5, ("error EPERM\n"));
+ return EPERM;
+ }
+ }
+ 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))
+ cons_unavail = FALSE;
+ /* were we in the middle of the vty switching process? */
+ if (scp->status & SWITCH_WAIT_REL) {
+ /* assert(scp == scp->sc->cur_scp) */
+ DPRINTF(5, ("reset WAIT_REL, "));
+ scp->status &= ~SWITCH_WAIT_REL;
+ s = do_switch_scr(sc, s);
+ }
+ if (scp->status & SWITCH_WAIT_ACQ) {
+ /* assert(scp == scp->sc->cur_scp) */
+ DPRINTF(5, ("reset WAIT_ACQ, "));
+ scp->status &= ~SWITCH_WAIT_ACQ;
+ sc->switch_in_progress = 0;
+ }
+ } 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, ", p->p_pid));
+ bcopy(data, &scp->smode, sizeof(struct vt_mode));
+ scp->proc = p;
+ scp->pid = scp->proc->p_pid;
+ if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
+ cons_unavail = TRUE;
+ }
+ splx(s);
+ DPRINTF(5, ("\n"));
+ return 0;
+ }
+
+ case VT_GETMODE: /* get screen switcher mode */
+ bcopy(&scp->smode, data, sizeof(struct vt_mode));
+ return 0;
+
+ 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 != p) {
+ splx(s);
+ return EPERM;
+ }
+ error = EINVAL;
+ switch(*(int *)data) {
+ case VT_FALSE: /* user refuses to release screen, abort */
+ if ((scp == sc->old_scp) && (scp->status & SWITCH_WAIT_REL)) {
+ sc->old_scp->status &= ~SWITCH_WAIT_REL;
+ sc->switch_in_progress = 0;
+ DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
+ error = 0;
+ }
+ break;
+
+ case VT_TRUE: /* user has released screen, go on */
+ if ((scp == sc->old_scp) && (scp->status & SWITCH_WAIT_REL)) {
+ scp->status &= ~SWITCH_WAIT_REL;
+ s = do_switch_scr(sc, s);
+ DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
+ error = 0;
+ }
+ break;
+
+ case VT_ACKACQ: /* acquire acknowledged, switch completed */
+ if ((scp == sc->new_scp) && (scp->status & SWITCH_WAIT_ACQ)) {
+ scp->status &= ~SWITCH_WAIT_ACQ;
+ sc->switch_in_progress = 0;
+ DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
+ error = 0;
+ }
+ 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 = VIRTUAL_TTY(sc, i);
+ if ((tp == NULL) || !(tp->t_state & TS_ISOPEN)) {
+ *(int *)data = i + 1;
+ return 0;
+ }
+ }
+ return EINVAL;
+
+ case VT_ACTIVATE: /* switch to screen *data */
+ s = spltty();
+ sc_clean_up(sc->cur_scp);
+ splx(s);
+ return switch_scr(sc, *(int *)data - 1);
+
+ case VT_WAITACTIVE: /* wait for switch to occur */
+ if ((*(int *)data >= sc->first_vty + sc->vtys)
+ || (*(int *)data < sc->first_vty))
+ return EINVAL;
+ s = spltty();
+ error = sc_clean_up(sc->cur_scp);
+ splx(s);
+ if (error)
+ return error;
+ if (*(int *)data != 0)
+ scp = SC_STAT(SC_DEV(sc, *(int *)data - 1));
+ if (scp == scp->sc->cur_scp)
+ return 0;
+ while ((error=tsleep((caddr_t)&scp->smode, PZERO|PCATCH,
+ "waitvt", 0)) == ERESTART) ;
+ 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 KDENABIO: /* allow io operations */
+ error = suser(p);
+ if (error != 0)
+ return error;
+ if (securelevel > 0)
+ return EPERM;
+#ifdef __i386__
+ p->p_md.md_regs->tf_eflags |= PSL_IOPL;
+#endif
+ return 0;
+
+ case KDDISABIO: /* disallow io operations (default) */
+#ifdef __i386__
+ p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
+#endif
+ return 0;
+
+ 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 = kbd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+ case KDSETRAD: /* set keyboard repeat & delay rates (old) */
+ if (*(int *)data & ~0x7f)
+ return EINVAL;
+ error = kbd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+ 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)
+ kbd_ioctl(sc->kbd, cmd, data);
+ return 0;
+ default:
+ return EINVAL;
+ }
+ /* NOT REACHED */
+
+ case KDGKBMODE: /* get keyboard mode */
+ *(int *)data = scp->kbd_mode;
+ return 0;
+
+ case KDGKBINFO:
+ error = kbd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+
+ case KDMKTONE: /* sound the bell */
+ if (*(int*)data)
+ do_bell(scp, (*(int*)data)&0xffff,
+ (((*(int*)data)>>16)&0xffff)*hz/1000);
+ else
+ do_bell(scp, scp->bell_pitch, scp->bell_duration);
+ return 0;
+
+ 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 = kbd_ioctl(sc->kbd, cmd, data);
+ if (error == ENOIOCTL) {
+ /* always return something? XXX */
+ *(int *)data = 0;
+ }
+ return 0;
+
+ 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 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;
+ kbd_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 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 = kbd_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))
+ copy_font(sc->cur_scp, LOAD, 8, sc->font_8);
+ 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))
+ copy_font(sc->cur_scp, LOAD, 14, sc->font_14);
+ 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))
+ copy_font(sc->cur_scp, LOAD, 16, sc->font_16);
+ 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;
+ }
+
+ error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
+ if (error != ENOIOCTL)
+ return(error);
+ error = ttioctl(tp, cmd, data, flag);
+ if (error != ENOIOCTL)
+ return(error);
+ return(ENOTTY);
+}
+
+static void
+scstart(struct tty *tp)
+{
+ struct clist *rbp;
+ int s, len;
+ u_char buf[PCBURST];
+ scr_stat *scp = SC_STAT(tp->t_dev);
+
+ if (scp->status & SLKED || scp->sc->blink_in_progress)
+ return;
+ s = spltty();
+ if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
+ tp->t_state |= TS_BUSY;
+ rbp = &tp->t_outq;
+ while (rbp->c_cc) {
+ len = q_to_b(rbp, buf, PCBURST);
+ splx(s);
+ ansi_put(scp, buf, len);
+ s = spltty();
+ }
+ tp->t_state &= ~TS_BUSY;
+ ttwwakeup(tp);
+ }
+ splx(s);
+}
+
+static void
+scmousestart(struct tty *tp)
+{
+ struct clist *rbp;
+ int s;
+ u_char buf[PCBURST];
+
+ s = spltty();
+ if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
+ tp->t_state |= TS_BUSY;
+ rbp = &tp->t_outq;
+ while (rbp->c_cc) {
+ q_to_b(rbp, buf, PCBURST);
+ }
+ tp->t_state &= ~TS_BUSY;
+ ttwwakeup(tp);
+ }
+ splx(s);
+}
+
+static void
+sccnprobe(struct consdev *cp)
+{
+#if __i386__
+ 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 */
+ cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLECTL);
+#endif /* __i386__ */
+
+#if __alpha__
+ /*
+ * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
+ * interface to install the console. Always return CN_DEAD from
+ * here.
+ */
+ cp->cn_pri = CN_DEAD;
+#endif /* __alpha__ */
+}
+
+static void
+sccninit(struct consdev *cp)
+{
+#if __i386__
+ int unit;
+ int flags;
+
+ sc_get_cons_priority(&unit, &flags);
+ scinit(unit, flags | SC_KERNEL_CONSOLE);
+ sc_console_unit = unit;
+ sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
+#endif /* __i386__ */
+
+#if __alpha__
+ /* SHOULDN'T REACH HERE */
+#endif /* __alpha__ */
+}
+
+static void
+sccnterm(struct consdev *cp)
+{
+ /* we are not the kernel console any more, release everything */
+
+ if (sc_console_unit < 0)
+ return; /* shouldn't happen */
+
+#if __i386__
+#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;
+#endif /* __i386__ */
+
+#if __alpha__
+ /* do nothing XXX */
+#endif /* __alpha__ */
+}
+
+#ifdef __alpha__
+
+void
+sccnattach(void)
+{
+ static struct consdev consdev;
+ int unit;
+ int flags;
+
+ bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
+ consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
+
+ /* a video card is always required */
+ if (!scvidprobe(unit, flags, TRUE))
+ consdev.cn_pri = CN_DEAD;
+
+ /* alpha doesn't allow the console being without a keyboard... Why? */
+ if (!sckbdprobe(unit, flags, TRUE))
+ consdev.cn_pri = CN_DEAD;
+
+ if (consdev.cn_pri == CN_DEAD)
+ return;
+
+ scinit(unit, flags | SC_KERNEL_CONSOLE);
+ sc_console_unit = unit;
+ sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
+ consdev.cn_dev = makedev(CDEV_MAJOR, 0);
+ cn_tab = &consdev;
+}
+
+#endif /* __alpha__ */
+
+static void
+sccnputc(dev_t dev, int c)
+{
+ u_char buf[1];
+ scr_stat *scp = sc_console;
+ term_stat save = scp->term;
+#ifndef SC_NO_HISTORY
+ struct tty *tp;
+#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;
+ draw_cursor_image(scp);
+ }
+ tp = VIRTUAL_TTY(scp->sc, scp->index);
+ if (tp->t_state & TS_ISOPEN)
+ scstart(tp);
+ }
+#endif /* !SC_NO_HISTORY */
+
+ scp->term = kernel_console;
+ current_default = &kernel_default;
+ buf[0] = c;
+ ansi_put(scp, buf, 1);
+ kernel_console = scp->term;
+ current_default = &user_default;
+ scp->term = save;
+
+ s = spltty(); /* block sckbdevent and scrn_timer */
+ sccnupdate(scp);
+ splx(s);
+}
+
+static int
+sccngetc(dev_t dev)
+{
+ return sccngetch(0);
+}
+
+static int
+sccncheckc(dev_t dev)
+{
+ return sccngetch(SCGETC_NONBLOCK);
+}
+
+static int
+sccngetch(int flags)
+{
+ 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.
+ */
+ kbd_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;
+ kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+
+ kbd_poll(scp->sc->kbd, TRUE);
+ c = scgetc(scp->sc, SCGETC_CN | flags);
+ kbd_poll(scp->sc->kbd, FALSE);
+
+ scp->kbd_mode = cur_mode;
+ kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ kbd_disable(scp->sc->kbd);
+ splx(s);
+
+ switch (KEYFLAGS(c)) {
+ case 0: /* normal char */
+ return KEYCHAR(c);
+ case FKEY: /* function key */
+ p = kbd_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 || scp->sc->videoio_in_progress)
+ return;
+
+ if (debugger || 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;
+#if NSPLASH > 0
+ 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 /* NSPLASH */
+
+ 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->status & SAVER_RUNNING))
+ scrn_update(scp, TRUE);
+}
+
+static void
+scrn_timer(void *arg)
+{
+ static int kbd_interval = 0;
+ 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 || sc->videoio_in_progress) {
+ if (again)
+ timeout(scrn_timer, sc, hz / 10);
+ return;
+ }
+ s = spltty();
+
+ if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
+ /* try to allocate a keyboard automatically */
+ if (++kbd_interval >= 25) {
+ sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
+ sckbdevent, sc);
+ if (sc->keyboard >= 0) {
+ sc->kbd = kbd_get_keyboard(sc->keyboard);
+ kbd_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;
+ }
+ }
+
+ /* find the vty to update */
+ scp = sc->cur_scp;
+
+ /* should we stop the screen saver? */
+ getmicrouptime(&tv);
+ if (debugger || 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;
+ }
+#if NSPLASH > 0
+ if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
+ if (sc->flags & SC_SCRN_BLANKED)
+ stop_scrn_saver(sc, current_saver);
+#endif /* NSPLASH */
+
+ /* 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) && !(scp->status & SAVER_RUNNING))
+ scrn_update(scp, TRUE);
+
+#if NSPLASH > 0
+ /* 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 /* NSPLASH */
+
+ 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) */
+
+ ++scp->sc->videoio_in_progress;
+
+#ifndef SC_NO_CUTPASTE
+ /* remove the previous mouse pointer image if necessary */
+ if ((scp->status & (MOUSE_VISIBLE | MOUSE_MOVED))
+ == (MOUSE_VISIBLE | MOUSE_MOVED)) {
+ /* FIXME: I don't like this... XXX */
+ 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;
+ --scp->sc->videoio_in_progress;
+ return;
+ }
+
+ /* update cursor image */
+ if (scp->status & CURSOR_ENABLED) {
+ /* did cursor move since last time ? */
+ if (scp->cursor_pos != scp->cursor_oldpos) {
+ /* do we need to remove old cursor image ? */
+ if (scp->cursor_oldpos < scp->start ||
+ scp->cursor_oldpos > scp->end) {
+ remove_cursor_image(scp);
+ }
+ scp->cursor_oldpos = scp->cursor_pos;
+ draw_cursor_image(scp);
+ }
+ else {
+ /* cursor didn't move, has it been overwritten ? */
+ if (scp->cursor_pos >= scp->start && scp->cursor_pos <= scp->end) {
+ draw_cursor_image(scp);
+ } else {
+ /* if its a blinking cursor, we may have to update it */
+ if (scp->sc->flags & SC_BLINK_CURSOR)
+ (*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->status & MOUSE_VISIBLE) {
+ /* did mouse move since last time ? */
+ if (scp->status & MOUSE_MOVED) {
+ /* the previous pointer image has been removed, see above */
+ scp->status &= ~MOUSE_MOVED;
+ sc_draw_mouse_image(scp);
+ } else {
+ /* mouse didn't move, has it been overwritten ? */
+ if (scp->mouse_pos + scp->xsize + 1 >= scp->start &&
+ scp->mouse_pos <= scp->end) {
+ sc_draw_mouse_image(scp);
+ } else if (scp->cursor_pos == scp->mouse_pos ||
+ scp->cursor_pos == scp->mouse_pos + 1 ||
+ scp->cursor_pos == scp->mouse_pos + scp->xsize ||
+ scp->cursor_pos == scp->mouse_pos + scp->xsize + 1) {
+ sc_draw_mouse_image(scp);
+ }
+ }
+ }
+#endif /* SC_NO_CUTPASTE */
+
+ scp->end = 0;
+ scp->start = scp->xsize*scp->ysize - 1;
+
+ --scp->sc->videoio_in_progress;
+}
+
+#if NSPLASH > 0
+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 | RB_CONFIG))) {
+ 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))
+ 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)
+ load_palette(scp->sc->adp, pal);
+#endif
+ 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))
+ draw_cursor_image(scp);
+ --scrn_blanked;
+ splx(s);
+ return 0;
+ }
+ if (set_mode(scp) == 0) {
+#ifndef SC_NO_PALETTE_LOADING
+ 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)
+ switch_scr(sc, sc->delayed_next_scr - 1);
+ wakeup((caddr_t)&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((caddr_t)&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
+ if ((error != 0) && (error != ERESTART))
+ break;
+ }
+ run_scrn_saver = FALSE;
+ return error;
+}
+#endif /* NSPLASH */
+
+void
+sc_touch_scrn_saver(void)
+{
+ scsplash_stick(FALSE);
+ run_scrn_saver = FALSE;
+}
+
+void
+sc_clear_screen(scr_stat *scp)
+{
+ move_crsr(scp, 0, 0);
+ scp->cursor_oldpos = scp->cursor_pos;
+ sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], scp->term.cur_color);
+ mark_all(scp);
+ sc_remove_cutmarking(scp);
+}
+
+static int
+switch_scr(sc_softc_t *sc, u_int next_scr)
+{
+ struct tty *tp;
+ int s;
+
+ DPRINTF(5, ("sc0: switch_scr() %d ", next_scr + 1));
+
+ /* 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->videoio_in_progress) {
+ sc->delayed_next_scr = next_scr + 1;
+ sc_touch_scrn_saver();
+ DPRINTF(5, ("switch delayed\n"));
+ return 0;
+ }
+
+ s = spltty();
+
+ /* we are in the middle of the vty switching process... */
+ if (sc->switch_in_progress
+ && (sc->cur_scp->smode.mode == VT_PROCESS)
+ && sc->cur_scp->proc) {
+ if (sc->cur_scp->proc != pfind(sc->cur_scp->pid)) {
+ /*
+ * 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, ",
+ sc->cur_scp->pid));
+ if (sc->cur_scp->status & SWITCH_WAIT_REL) {
+ /*
+ * Force the previous switch to finish, but return now
+ * with error.
+ */
+ DPRINTF(5, ("reset WAIT_REL, "));
+ sc->cur_scp->status &= ~SWITCH_WAIT_REL;
+ s = do_switch_scr(sc, s);
+ splx(s);
+ DPRINTF(5, ("finishing previous switch\n"));
+ return EINVAL;
+ } else if (sc->cur_scp->status & SWITCH_WAIT_ACQ) {
+ /* let's assume screen switch has been completed. */
+ DPRINTF(5, ("reset WAIT_ACQ, "));
+ sc->cur_scp->status &= ~SWITCH_WAIT_ACQ;
+ sc->switch_in_progress = 0;
+ } 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 {
+ /*
+ * 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 (sc->cur_scp->status & SWITCH_WAIT_REL) {
+ switch (sc->switch_in_progress++) {
+ case 1:
+ break;
+ case 2:
+ DPRINTF(5, ("sending relsig again, "));
+ signal_vt_rel(sc->cur_scp);
+ break;
+ case 3:
+ break;
+ case 4:
+ default:
+ /*
+ * Act as if the controlling program returned
+ * VT_FALSE.
+ */
+ DPRINTF(5, ("force reset WAIT_REL, "));
+ sc->cur_scp->status &= ~SWITCH_WAIT_REL;
+ sc->switch_in_progress = 0;
+ splx(s);
+ DPRINTF(5, ("act as if VT_FALSE was seen\n"));
+ return EINVAL;
+ }
+ } else if (sc->cur_scp->status & SWITCH_WAIT_ACQ) {
+ switch (sc->switch_in_progress++) {
+ case 1:
+ break;
+ case 2:
+ DPRINTF(5, ("sending acqsig again, "));
+ signal_vt_acq(sc->cur_scp);
+ break;
+ case 3:
+ break;
+ case 4:
+ default:
+ /* clear the flag and finish the previous switch */
+ DPRINTF(5, ("force reset WAIT_ACQ, "));
+ sc->cur_scp->status &= ~SWITCH_WAIT_ACQ;
+ sc->switch_in_progress = 0;
+ 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);
+ do_bell(sc->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 = VIRTUAL_TTY(sc, sc->cur_scp->index);
+ if ((sc->cur_scp->index != next_scr)
+ && (tp->t_state & TS_ISOPEN)
+ && (sc->cur_scp->smode.mode == VT_AUTO)
+ && ISGRAPHSC(sc->cur_scp)) {
+ splx(s);
+ do_bell(sc->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.
+ * 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 = VIRTUAL_TTY(sc, next_scr);
+ if ((tp == NULL) || !(tp->t_state & TS_ISOPEN)) {
+ splx(s);
+ do_bell(sc->cur_scp, bios_value.bell_pitch, BELL_DURATION);
+ DPRINTF(5, ("error 2, requested vty isn't open!\n"));
+ return EINVAL;
+ }
+ }
+
+ /* this is the start of vty switching process... */
+ ++sc->switch_in_progress;
+ sc->delayed_next_scr = 0;
+ sc->old_scp = sc->cur_scp;
+ sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
+ if (sc->new_scp == sc->old_scp) {
+ sc->switch_in_progress = 0;
+ wakeup((caddr_t)&sc->new_scp->smode);
+ 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 */
+ wakeup((caddr_t)&sc->cur_scp->smode);
+
+ /* 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)
+ cons_unavail = FALSE;
+ 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((caddr_t)&sc->cur_scp->smode);
+
+ /* 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)
+ cons_unavail = FALSE;
+ }
+
+ return s;
+}
+
+static int
+vt_proc_alive(scr_stat *scp)
+{
+ if (scp->proc) {
+ if (scp->proc == pfind(scp->pid))
+ 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;
+ psignal(scp->proc, scp->smode.relsig);
+ 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)
+ cons_unavail = TRUE;
+ scp->status |= SWITCH_WAIT_ACQ;
+ psignal(scp->proc, scp->smode.acqsig);
+ DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
+ return TRUE;
+}
+
+static void
+exchange_scr(sc_softc_t *sc)
+{
+ scr_stat *scp;
+
+ /* save the current state of video and keyboard */
+ move_crsr(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
+ 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;
+ if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
+ set_mode(scp);
+ else
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
+ (void *)sc->adp->va_window, FALSE);
+ move_crsr(scp, scp->xpos, scp->ypos);
+ if (!ISGRAPHSC(scp))
+ sc_set_cursor_image(scp);
+#ifndef SC_NO_PALETTE_LOADING
+ if (ISGRAPHSC(sc->old_scp))
+ load_palette(sc->adp, sc->palette);
+#endif
+ set_border(scp, scp->border);
+
+ /* set up the keyboard for the new screen */
+ if (sc->old_scp->kbd_mode != scp->kbd_mode)
+ kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
+ update_kbd_state(scp, scp->status, LOCK_MASK);
+
+ mark_all(scp);
+}
+
+static void
+scan_esc(scr_stat *scp, u_char c)
+{
+ static u_char ansi_col[16] =
+ {0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15};
+ sc_softc_t *sc;
+ int i, n;
+ int count;
+
+ i = n = 0;
+ sc = scp->sc;
+ if (scp->term.esc == 1) { /* seen ESC */
+ switch (c) {
+
+ case '7': /* Save cursor position */
+ scp->saved_xpos = scp->xpos;
+ scp->saved_ypos = scp->ypos;
+ break;
+
+ case '8': /* Restore saved cursor position */
+ if (scp->saved_xpos >= 0 && scp->saved_ypos >= 0)
+ move_crsr(scp, scp->saved_xpos, scp->saved_ypos);
+ break;
+
+ case '[': /* Start ESC [ sequence */
+ scp->term.esc = 2;
+ scp->term.last_param = -1;
+ for (i = scp->term.num_param; i < MAX_ESC_PAR; i++)
+ scp->term.param[i] = 1;
+ scp->term.num_param = 0;
+ return;
+
+ case 'M': /* Move cursor up 1 line, scroll if at top */
+ if (scp->ypos > 0)
+ move_crsr(scp, scp->xpos, scp->ypos - 1);
+ else {
+ sc_vtb_ins(&scp->vtb, 0, scp->xsize,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_all(scp);
+ }
+ break;
+#if notyet
+ case 'Q':
+ scp->term.esc = 4;
+ return;
+#endif
+ case 'c': /* Clear screen & home */
+ sc_clear_screen(scp);
+ break;
+
+ case '(': /* iso-2022: designate 94 character set to G0 */
+ scp->term.esc = 5;
+ return;
+ }
+ }
+ else if (scp->term.esc == 2) { /* seen ESC [ */
+ if (c >= '0' && c <= '9') {
+ if (scp->term.num_param < MAX_ESC_PAR) {
+ if (scp->term.last_param != scp->term.num_param) {
+ scp->term.last_param = scp->term.num_param;
+ scp->term.param[scp->term.num_param] = 0;
+ }
+ else
+ scp->term.param[scp->term.num_param] *= 10;
+ scp->term.param[scp->term.num_param] += c - '0';
+ return;
+ }
+ }
+ scp->term.num_param = scp->term.last_param + 1;
+ switch (c) {
+
+ case ';':
+ if (scp->term.num_param < MAX_ESC_PAR)
+ return;
+ break;
+
+ case '=':
+ scp->term.esc = 3;
+ scp->term.last_param = -1;
+ for (i = scp->term.num_param; i < MAX_ESC_PAR; i++)
+ scp->term.param[i] = 1;
+ scp->term.num_param = 0;
+ return;
+
+ case 'A': /* up n rows */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos, scp->ypos - n);
+ break;
+
+ case 'B': /* down n rows */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos, scp->ypos + n);
+ break;
+
+ case 'C': /* right n columns */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos + n, scp->ypos);
+ break;
+
+ case 'D': /* left n columns */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos - n, scp->ypos);
+ break;
+
+ case 'E': /* cursor to start of line n lines down */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, 0, scp->ypos + n);
+ break;
+
+ case 'F': /* cursor to start of line n lines up */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, 0, scp->ypos - n);
+ break;
+
+ case 'f': /* Cursor move */
+ case 'H':
+ if (scp->term.num_param == 0)
+ move_crsr(scp, 0, 0);
+ else if (scp->term.num_param == 2)
+ move_crsr(scp, scp->term.param[1] - 1, scp->term.param[0] - 1);
+ break;
+
+ case 'J': /* Clear all or part of display */
+ if (scp->term.num_param == 0)
+ n = 0;
+ else
+ n = scp->term.param[0];
+ switch (n) {
+ case 0: /* clear form cursor to end of display */
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos,
+ scp->xsize * scp->ysize - scp->cursor_pos,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->cursor_pos);
+ mark_for_update(scp, scp->xsize * scp->ysize - 1);
+ sc_remove_cutmarking(scp);
+ break;
+ case 1: /* clear from beginning of display to cursor */
+ sc_vtb_erase(&scp->vtb, 0, scp->cursor_pos,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, 0);
+ mark_for_update(scp, scp->cursor_pos);
+ sc_remove_cutmarking(scp);
+ break;
+ case 2: /* clear entire display */
+ sc_vtb_clear(&scp->vtb, sc->scr_map[0x20], scp->term.cur_color);
+ mark_all(scp);
+ sc_remove_cutmarking(scp);
+ break;
+ }
+ break;
+
+ case 'K': /* Clear all or part of line */
+ if (scp->term.num_param == 0)
+ n = 0;
+ else
+ n = scp->term.param[0];
+ switch (n) {
+ case 0: /* clear form cursor to end of line */
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos,
+ scp->xsize - scp->xpos,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->cursor_pos);
+ mark_for_update(scp, scp->cursor_pos +
+ scp->xsize - 1 - scp->xpos);
+ break;
+ case 1: /* clear from beginning of line to cursor */
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
+ scp->xpos + 1,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->ypos * scp->xsize);
+ mark_for_update(scp, scp->cursor_pos);
+ break;
+ case 2: /* clear entire line */
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos - scp->xpos,
+ scp->xsize,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->ypos * scp->xsize);
+ mark_for_update(scp, (scp->ypos + 1) * scp->xsize - 1);
+ break;
+ }
+ break;
+
+ case 'L': /* Insert n lines */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->ysize - scp->ypos)
+ n = scp->ysize - scp->ypos;
+ sc_vtb_ins(&scp->vtb, scp->ypos * scp->xsize, n * scp->xsize,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->ypos * scp->xsize);
+ mark_for_update(scp, scp->xsize * scp->ysize - 1);
+ break;
+
+ case 'M': /* Delete n lines */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->ysize - scp->ypos)
+ n = scp->ysize - scp->ypos;
+ sc_vtb_delete(&scp->vtb, scp->ypos * scp->xsize, n * scp->xsize,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->ypos * scp->xsize);
+ mark_for_update(scp, scp->xsize * scp->ysize - 1);
+ break;
+
+ case 'P': /* Delete n chars */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->xsize - scp->xpos)
+ n = scp->xsize - scp->xpos;
+ count = scp->xsize - (scp->xpos + n);
+ sc_vtb_move(&scp->vtb, scp->cursor_pos + n, scp->cursor_pos, count);
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos + count, n,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->cursor_pos);
+ mark_for_update(scp, scp->cursor_pos + n + count - 1);
+ break;
+
+ case '@': /* Insert n chars */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->xsize - scp->xpos)
+ n = scp->xsize - scp->xpos;
+ count = scp->xsize - (scp->xpos + n);
+ sc_vtb_move(&scp->vtb, scp->cursor_pos, scp->cursor_pos + n, count);
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos, n,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->cursor_pos);
+ mark_for_update(scp, scp->cursor_pos + n + count - 1);
+ break;
+
+ case 'S': /* scroll up n lines */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->ysize)
+ n = scp->ysize;
+ sc_vtb_delete(&scp->vtb, 0, n * scp->xsize,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_all(scp);
+ break;
+
+ case 'T': /* scroll down n lines */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->ysize)
+ n = scp->ysize;
+ sc_vtb_ins(&scp->vtb, 0, n * scp->xsize,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_all(scp);
+ break;
+
+ case 'X': /* erase n characters in line */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if (n > scp->xsize - scp->xpos)
+ n = scp->xsize - scp->xpos;
+ sc_vtb_erase(&scp->vtb, scp->cursor_pos, n,
+ sc->scr_map[0x20], scp->term.cur_color);
+ mark_for_update(scp, scp->cursor_pos);
+ mark_for_update(scp, scp->cursor_pos + n - 1);
+ break;
+
+ case 'Z': /* move n tabs backwards */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ if ((i = scp->xpos & 0xf8) == scp->xpos)
+ i -= 8*n;
+ else
+ i -= 8*(n-1);
+ if (i < 0)
+ i = 0;
+ move_crsr(scp, i, scp->ypos);
+ break;
+
+ case '`': /* move cursor to column n */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, n - 1, scp->ypos);
+ break;
+
+ case 'a': /* move cursor n columns to the right */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos + n, scp->ypos);
+ break;
+
+ case 'd': /* move cursor to row n */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos, n - 1);
+ break;
+
+ case 'e': /* move cursor n rows down */
+ n = scp->term.param[0]; if (n < 1) n = 1;
+ move_crsr(scp, scp->xpos, scp->ypos + n);
+ break;
+
+ case 'm': /* change attribute */
+ if (scp->term.num_param == 0) {
+ scp->term.attr_mask = NORMAL_ATTR;
+ scp->term.cur_attr =
+ scp->term.cur_color = scp->term.std_color;
+ break;
+ }
+ for (i = 0; i < scp->term.num_param; i++) {
+ switch (n = scp->term.param[i]) {
+ case 0: /* back to normal */
+ scp->term.attr_mask = NORMAL_ATTR;
+ scp->term.cur_attr =
+ scp->term.cur_color = scp->term.std_color;
+ break;
+ case 1: /* bold */
+ scp->term.attr_mask |= BOLD_ATTR;
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 4: /* underline */
+ scp->term.attr_mask |= UNDERLINE_ATTR;
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 5: /* blink */
+ scp->term.attr_mask |= BLINK_ATTR;
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 7: /* reverse video */
+ scp->term.attr_mask |= REVERSE_ATTR;
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 30: case 31: /* set fg color */
+ case 32: case 33: case 34:
+ case 35: case 36: case 37:
+ scp->term.attr_mask |= FOREGROUND_CHANGED;
+ scp->term.cur_color =
+ (scp->term.cur_color&0xF000) | (ansi_col[(n-30)&7]<<8);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 40: case 41: /* set bg color */
+ case 42: case 43: case 44:
+ case 45: case 46: case 47:
+ scp->term.attr_mask |= BACKGROUND_CHANGED;
+ scp->term.cur_color =
+ (scp->term.cur_color&0x0F00) | (ansi_col[(n-40)&7]<<12);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ }
+ }
+ break;
+
+ case 's': /* Save cursor position */
+ scp->saved_xpos = scp->xpos;
+ scp->saved_ypos = scp->ypos;
+ break;
+
+ case 'u': /* Restore saved cursor position */
+ if (scp->saved_xpos >= 0 && scp->saved_ypos >= 0)
+ move_crsr(scp, scp->saved_xpos, scp->saved_ypos);
+ break;
+
+ case 'x':
+ if (scp->term.num_param == 0)
+ n = 0;
+ else
+ n = scp->term.param[0];
+ switch (n) {
+ case 0: /* reset attributes */
+ scp->term.attr_mask = NORMAL_ATTR;
+ scp->term.cur_attr =
+ scp->term.cur_color = scp->term.std_color =
+ current_default->std_color;
+ scp->term.rev_color = current_default->rev_color;
+ break;
+ case 1: /* set ansi background */
+ scp->term.attr_mask &= ~BACKGROUND_CHANGED;
+ scp->term.cur_color = scp->term.std_color =
+ (scp->term.std_color & 0x0F00) |
+ (ansi_col[(scp->term.param[1])&0x0F]<<12);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 2: /* set ansi foreground */
+ scp->term.attr_mask &= ~FOREGROUND_CHANGED;
+ scp->term.cur_color = scp->term.std_color =
+ (scp->term.std_color & 0xF000) |
+ (ansi_col[(scp->term.param[1])&0x0F]<<8);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 3: /* set ansi attribute directly */
+ scp->term.attr_mask &= ~(FOREGROUND_CHANGED|BACKGROUND_CHANGED);
+ scp->term.cur_color = scp->term.std_color =
+ (scp->term.param[1]&0xFF)<<8;
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 5: /* set ansi reverse video background */
+ scp->term.rev_color =
+ (scp->term.rev_color & 0x0F00) |
+ (ansi_col[(scp->term.param[1])&0x0F]<<12);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 6: /* set ansi reverse video foreground */
+ scp->term.rev_color =
+ (scp->term.rev_color & 0xF000) |
+ (ansi_col[(scp->term.param[1])&0x0F]<<8);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ case 7: /* set ansi reverse video directly */
+ scp->term.rev_color =
+ (scp->term.param[1]&0xFF)<<8;
+ scp->term.cur_attr = mask2attr(&scp->term);
+ break;
+ }
+ break;
+
+ case 'z': /* switch to (virtual) console n */
+ if (scp->term.num_param == 1)
+ switch_scr(sc, scp->term.param[0]);
+ break;
+ }
+ }
+ else if (scp->term.esc == 3) { /* seen ESC [0-9]+ = */
+ if (c >= '0' && c <= '9') {
+ if (scp->term.num_param < MAX_ESC_PAR) {
+ if (scp->term.last_param != scp->term.num_param) {
+ scp->term.last_param = scp->term.num_param;
+ scp->term.param[scp->term.num_param] = 0;
+ }
+ else
+ scp->term.param[scp->term.num_param] *= 10;
+ scp->term.param[scp->term.num_param] += c - '0';
+ return;
+ }
+ }
+ scp->term.num_param = scp->term.last_param + 1;
+ switch (c) {
+
+ case ';':
+ if (scp->term.num_param < MAX_ESC_PAR)
+ return;
+ break;
+
+ case 'A': /* set display border color */
+ if (scp->term.num_param == 1) {
+ scp->border=scp->term.param[0] & 0xff;
+ if (scp == sc->cur_scp)
+ set_border(scp, scp->border);
+ }
+ break;
+
+ case 'B': /* set bell pitch and duration */
+ if (scp->term.num_param == 2) {
+ scp->bell_pitch = scp->term.param[0];
+ scp->bell_duration = scp->term.param[1];
+ }
+ break;
+
+ case 'C': /* set cursor type & shape */
+ if (!ISGRAPHSC(sc->cur_scp))
+ remove_cursor_image(sc->cur_scp);
+ if (scp->term.num_param == 1) {
+ if (scp->term.param[0] & 0x01)
+ sc->flags |= SC_BLINK_CURSOR;
+ else
+ sc->flags &= ~SC_BLINK_CURSOR;
+ if (scp->term.param[0] & 0x02)
+ sc->flags |= SC_CHAR_CURSOR;
+ else
+ sc->flags &= ~SC_CHAR_CURSOR;
+ }
+ else if (scp->term.num_param == 2) {
+ sc->cursor_base = scp->font_size
+ - (scp->term.param[1] & 0x1F) - 1;
+ sc->cursor_height = (scp->term.param[1] & 0x1F)
+ - (scp->term.param[0] & 0x1F) + 1;
+ }
+ /*
+ * The cursor shape is global property; all virtual consoles
+ * are affected. Update the cursor in the current console...
+ */
+ if (!ISGRAPHSC(sc->cur_scp)) {
+ i = spltty();
+ sc_set_cursor_image(sc->cur_scp);
+ draw_cursor_image(sc->cur_scp);
+ splx(i);
+ }
+ break;
+
+ case 'F': /* set ansi foreground */
+ if (scp->term.num_param == 1) {
+ scp->term.attr_mask &= ~FOREGROUND_CHANGED;
+ scp->term.cur_color = scp->term.std_color =
+ (scp->term.std_color & 0xF000)
+ | ((scp->term.param[0] & 0x0F) << 8);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ }
+ break;
+
+ case 'G': /* set ansi background */
+ if (scp->term.num_param == 1) {
+ scp->term.attr_mask &= ~BACKGROUND_CHANGED;
+ scp->term.cur_color = scp->term.std_color =
+ (scp->term.std_color & 0x0F00)
+ | ((scp->term.param[0] & 0x0F) << 12);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ }
+ break;
+
+ case 'H': /* set ansi reverse video foreground */
+ if (scp->term.num_param == 1) {
+ scp->term.rev_color =
+ (scp->term.rev_color & 0xF000)
+ | ((scp->term.param[0] & 0x0F) << 8);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ }
+ break;
+
+ case 'I': /* set ansi reverse video background */
+ if (scp->term.num_param == 1) {
+ scp->term.rev_color =
+ (scp->term.rev_color & 0x0F00)
+ | ((scp->term.param[0] & 0x0F) << 12);
+ scp->term.cur_attr = mask2attr(&scp->term);
+ }
+ break;
+ }
+ }
+#if notyet
+ else if (scp->term.esc == 4) { /* seen ESC Q */
+ /* to be filled */
+ }
+#endif
+ else if (scp->term.esc == 5) { /* seen ESC ( */
+ switch (c) {
+ case 'B': /* iso-2022: desginate ASCII into G0 */
+ break;
+ /* other items to be filled */
+ default:
+ break;
+ }
+ }
+ scp->term.esc = 0;
+}
+
+static void
+ansi_put(scr_stat *scp, u_char *buf, int len)
+{
+ u_char *ptr = buf;
+
+#if NSPLASH > 0
+ /* make screensaver happy */
+ if (!sticky_splash && scp == scp->sc->cur_scp)
+ run_scrn_saver = FALSE;
+#endif
+
+outloop:
+ scp->sc->write_in_progress++;
+ if (scp->term.esc) {
+ scan_esc(scp, *ptr++);
+ len--;
+ }
+ else if (PRINTABLE(*ptr)) { /* Print only printables */
+ vm_offset_t p;
+ u_char *map;
+ int cnt;
+ int attr;
+ int i;
+
+ p = sc_vtb_pointer(&scp->vtb, scp->cursor_pos);
+ map = scp->sc->scr_map;
+ attr = scp->term.cur_attr;
+
+ cnt = (len <= scp->xsize - scp->xpos) ? len : (scp->xsize - scp->xpos);
+ i = cnt;
+ do {
+ /*
+ * gcc-2.6.3 generates poor (un)sign extension code. Casting the
+ * pointers in the following to volatile should have no effect,
+ * but in fact speeds up this inner loop from 26 to 18 cycles
+ * (+ cache misses) on i486's.
+ */
+#define UCVP(ucp) ((u_char volatile *)(ucp))
+ p = sc_vtb_putchar(&scp->vtb, p, UCVP(map)[*UCVP(ptr)], attr);
+ ++ptr;
+ --i;
+ } while (i > 0 && PRINTABLE(*ptr));
+
+ len -= cnt - i;
+ mark_for_update(scp, scp->cursor_pos);
+ scp->cursor_pos += cnt - i;
+ mark_for_update(scp, scp->cursor_pos - 1);
+ scp->xpos += cnt - i;
+
+ if (scp->xpos >= scp->xsize) {
+ scp->xpos = 0;
+ scp->ypos++;
+ }
+ }
+ else {
+ switch(*ptr) {
+ case 0x07:
+ do_bell(scp, scp->bell_pitch, scp->bell_duration);
+ break;
+
+ case 0x08: /* non-destructive backspace */
+ if (scp->cursor_pos > 0) {
+ mark_for_update(scp, scp->cursor_pos);
+ scp->cursor_pos--;
+ mark_for_update(scp, scp->cursor_pos);
+ if (scp->xpos > 0)
+ scp->xpos--;
+ else {
+ scp->xpos += scp->xsize - 1;
+ scp->ypos--;
+ }
+ }
+ break;
+
+ case 0x09: /* non-destructive tab */
+ mark_for_update(scp, scp->cursor_pos);
+ scp->cursor_pos += (8 - scp->xpos % 8u);
+ if ((scp->xpos += (8 - scp->xpos % 8u)) >= scp->xsize) {
+ scp->xpos = 0;
+ scp->ypos++;
+ scp->cursor_pos = scp->xsize * scp->ypos;
+ }
+ mark_for_update(scp, scp->cursor_pos);
+ break;
+
+ case 0x0a: /* newline, same pos */
+ mark_for_update(scp, scp->cursor_pos);
+ scp->cursor_pos += scp->xsize;
+ mark_for_update(scp, scp->cursor_pos);
+ scp->ypos++;
+ break;
+
+ case 0x0c: /* form feed, clears screen */
+ sc_clear_screen(scp);
+ break;
+
+ case 0x0d: /* return, return to pos 0 */
+ mark_for_update(scp, scp->cursor_pos);
+ scp->cursor_pos -= scp->xpos;
+ mark_for_update(scp, scp->cursor_pos);
+ scp->xpos = 0;
+ break;
+
+ case 0x1b: /* start escape sequence */
+ scp->term.esc = 1;
+ scp->term.num_param = 0;
+ break;
+ }
+ ptr++; len--;
+ }
+ /* do we have to scroll ?? */
+ if (scp->cursor_pos >= scp->ysize * scp->xsize) {
+ sc_remove_cutmarking(scp);
+#ifndef SC_NO_HISTORY
+ if (scp->history != NULL)
+ sc_hist_save_one_line(scp, 0);
+#endif
+ sc_vtb_delete(&scp->vtb, 0, scp->xsize,
+ scp->sc->scr_map[0x20], scp->term.cur_color);
+ scp->cursor_pos -= scp->xsize;
+ scp->ypos--;
+ mark_all(scp);
+ }
+ scp->sc->write_in_progress--;
+ if (len)
+ goto outloop;
+ if (scp->sc->delayed_next_scr)
+ switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
+}
+
+static void
+draw_cursor_image(scr_stat *scp)
+{
+ /* assert(scp == scp->sc->cur_scp); */
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
+ scp->sc->flags & SC_BLINK_CURSOR, TRUE,
+ sc_inside_cutmark(scp, scp->cursor_pos));
+ --scp->sc->videoio_in_progress;
+}
+
+static void
+remove_cursor_image(scr_stat *scp)
+{
+ /* assert(scp == scp->sc->cur_scp); */
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
+ scp->sc->flags & SC_BLINK_CURSOR, FALSE,
+ sc_inside_cutmark(scp, scp->cursor_oldpos));
+ --scp->sc->videoio_in_progress;
+}
+
+static void
+update_cursor_image(scr_stat *scp)
+{
+ int blink;
+
+ if (scp->sc->flags & SC_CHAR_CURSOR) {
+ scp->cursor_base = scp->sc->cursor_base;
+ scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
+ } else {
+ scp->cursor_base = 0;
+ scp->cursor_height = scp->font_size;
+ }
+ blink = scp->sc->flags & SC_BLINK_CURSOR;
+
+ /* assert(scp == scp->sc->cur_scp); */
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
+ sc_inside_cutmark(scp, scp->cursor_pos));
+ (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
+ (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
+ sc_inside_cutmark(scp, scp->cursor_pos));
+ --scp->sc->videoio_in_progress;
+}
+
+void
+sc_set_cursor_image(scr_stat *scp)
+{
+ if (scp->sc->flags & SC_CHAR_CURSOR) {
+ scp->cursor_base = scp->sc->cursor_base;
+ scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
+ } else {
+ scp->cursor_base = 0;
+ scp->cursor_height = scp->font_size;
+ }
+
+ /* assert(scp == scp->sc->cur_scp); */
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
+ scp->sc->flags & SC_BLINK_CURSOR);
+ --scp->sc->videoio_in_progress;
+}
+
+static void
+move_crsr(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;
+}
+
+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
+ */
+ static scr_stat main_console;
+ static dev_t main_devs[MAXCONS];
+ static struct tty main_tty;
+ static u_short sc_buffer[ROW*COL]; /* XXX */
+#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);
+ current_default = &user_default;
+ /* kernel console attributes */
+ kernel_console.esc = 0;
+ kernel_console.attr_mask = NORMAL_ATTR;
+ kernel_console.cur_attr =
+ kernel_console.cur_color = kernel_console.std_color =
+ kernel_default.std_color;
+ kernel_console.rev_color = kernel_default.rev_color;
+ }
+ 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);
+ 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, minor:%d, flags:0x%x\n",
+ unit, sc->kbd->kb_index, sc->kbd->kb_minor, 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 = kbd_allocate("*", unit, (void *)&sc->keyboard,
+ sckbdevent, sc);
+ 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, minor:%d, flags:0x%x\n",
+ unit, sc->kbd->kb_index, sc->kbd->kb_minor, 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 */
+ (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
+ (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
+
+ /* set up the first console */
+ sc->first_vty = unit*MAXCONS;
+ sc->vtys = MAXCONS;
+ if (flags & SC_KERNEL_CONSOLE) {
+ sc->dev = main_devs;
+ sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
+ sc->dev[0]->si_tty = &main_tty;
+ ttyregister(&main_tty);
+ 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);
+ } else {
+ /* assert(sc_malloc) */
+ sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
+ bzero(sc->dev, sizeof(dev_t)*sc->vtys);
+ sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
+ sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
+ scp = alloc_scp(sc, sc->first_vty);
+ }
+ SC_STAT(sc->dev[0]) = scp;
+ sc->cur_scp = scp;
+
+ /* 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);
+
+ /* move cursors to the initial positions */
+ scp->mouse_pos = scp->mouse_oldpos = 0;
+ 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 (bios_value.cursor_end < scp->font_size)
+ sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
+ else
+ sc->cursor_base = 0;
+ i = bios_value.cursor_end - bios_value.cursor_start + 1;
+ sc->cursor_height = imin(i, scp->font_size);
+ if (!ISGRAPHSC(scp)) {
+ sc_set_cursor_image(scp);
+ 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) {
+ copy_font(scp, LOAD, 8, sc->font_8);
+ } else if (scp->font_size >= 16) {
+ copy_font(scp, LOAD, 16, sc->font_16);
+ } else {
+ copy_font(scp, LOAD, 14, sc->font_14);
+ }
+#else /* !SC_DFLT_FONT */
+ if (scp->font_size < 14) {
+ copy_font(scp, SAVE, 8, sc->font_8);
+ sc->fonts_loaded = FONT_8;
+ } else if (scp->font_size >= 16) {
+ copy_font(scp, SAVE, 16, sc->font_16);
+ sc->fonts_loaded = FONT_16;
+ } else {
+ copy_font(scp, SAVE, 14, sc->font_14);
+ sc->fonts_loaded = FONT_14;
+ }
+#endif /* SC_DFLT_FONT */
+ /* FONT KLUDGE: always use the font page #0. XXX */
+ (*vidsw[sc->adapter]->show_font)(sc->adp, 0);
+ }
+#endif /* !SC_NO_FONT_LOADING */
+
+#ifndef SC_NO_PALETTE_LOADING
+ save_palette(sc->adp, sc->palette);
+#endif
+
+#if NSPLASH > 0
+ if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
+ /* we are ready to put up the splash image! */
+ splash_init(sc->adp, scsplash_callback, sc);
+ sc->flags |= SC_SPLASH_SCRN;
+ }
+#endif /* NSPLASH */
+ }
+
+ /* 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;
+
+ sc->flags |= SC_INIT_DONE;
+}
+
+#if __i386__
+static void
+scterm(int unit, int flags)
+{
+ sc_softc_t *sc;
+
+ sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
+ if (sc == NULL)
+ return; /* shouldn't happen */
+
+#if NSPLASH > 0
+ /* 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 /* NSPLASH */
+
+#if 0 /* XXX */
+ /* move the hardware cursor to the upper-left corner */
+ (*vidsw[sc->adapter]->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);
+
+ /* 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;
+}
+#endif
+
+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)
+ switch_scr(sc_console->sc, sc_console->index);
+ shutdown_in_progress = TRUE;
+}
+
+int
+sc_clean_up(scr_stat *scp)
+{
+#if NSPLASH > 0
+ int error;
+#endif /* NSPLASH */
+
+ sc_touch_scrn_saver();
+#if NSPLASH > 0
+ if ((error = wait_scrn_saver_stop(scp->sc)))
+ return error;
+#endif /* NSPLASH */
+ scp->status &= ~MOUSE_VISIBLE;
+ 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;
+ int s;
+
+ 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 {
+ /* clear the screen and move the text cursor to the top-left position */
+ s = splhigh();
+ scp->vtb = new;
+ sc_clear_screen(scp);
+ splx(s);
+ 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);
+
+#ifndef SC_NO_SYSMOUSE
+ if (ISMOUSEAVAIL(sc->adp->va_flags))
+ sc_alloc_cut_buffer(scp, TRUE);
+#endif
+
+#ifndef SC_NO_HISTORY
+ sc_alloc_history_buffer(scp, 0, 0, TRUE);
+#endif
+
+ sc_clear_screen(scp);
+ return scp;
+}
+
+static void
+init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
+{
+ video_info_t info;
+
+ scp->index = vty;
+ scp->sc = sc;
+ scp->status = 0;
+ scp->mode = sc->initial_mode;
+ (*vidsw[sc->adapter]->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/8;
+ scp->ysize = info.vi_height/info.vi_cheight;
+ scp->font_size = FONT_NONE;
+ scp->font = NULL;
+ } else {
+ scp->xsize = info.vi_width;
+ scp->ysize = info.vi_height;
+ scp->xpixel = scp->xsize*8;
+ scp->ypixel = scp->ysize*info.vi_cheight;
+ if (info.vi_cheight < 14) {
+ scp->font_size = 8;
+#ifndef SC_NO_FONT_LOADING
+ scp->font = sc->font_8;
+#else
+ scp->font = NULL;
+#endif
+ } else if (info.vi_cheight >= 16) {
+ scp->font_size = 16;
+#ifndef SC_NO_FONT_LOADING
+ scp->font = sc->font_16;
+#else
+ scp->font = NULL;
+#endif
+ } else {
+ scp->font_size = 14;
+#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);
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
+ scp->xoff = scp->yoff = 0;
+ scp->xpos = scp->ypos = 0;
+ scp->saved_xpos = scp->saved_ypos = -1;
+ scp->start = scp->xsize * scp->ysize - 1;
+ scp->end = 0;
+ scp->term.esc = 0;
+ scp->term.attr_mask = NORMAL_ATTR;
+ scp->term.cur_attr =
+ scp->term.cur_color = scp->term.std_color =
+ current_default->std_color;
+ scp->term.rev_color = current_default->rev_color;
+ scp->border = BG_BLACK;
+ scp->cursor_base = sc->cursor_base;
+ scp->cursor_height = imin(sc->cursor_height, scp->font_size);
+ scp->mouse_xpos = scp->xoff*8 + scp->xsize*8/2;
+ scp->mouse_ypos = (scp->ysize + scp->yoff)*scp->font_size/2;
+ 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;
+ scp->pid = 0;
+ scp->proc = NULL;
+ scp->smode.mode = VT_AUTO;
+ scp->history = NULL;
+ scp->history_pos = 0;
+ scp->history_size = 0;
+
+ /* what if the following call fails... XXX */
+ scp->rndr = sc_render_match(scp, scp->sc->adp,
+ scp->status & (GRAPHICS_MODE | PIXEL_MODE));
+}
+
+/*
+ * 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 = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
+ if (c == ERRKEY) {
+ if (!(flags & SCGETC_CN))
+ do_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();
+
+#ifdef __i386__
+ if (!(flags & SCGETC_CN))
+ /* do the /dev/random device a favour */
+ add_keyboard_randomness(c);
+#endif
+
+ 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;
+ 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))
+ do_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))
+ do_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))
+ do_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))
+ do_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:
+ kbd_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;
+ draw_cursor_image(scp);
+ }
+ tp = VIRTUAL_TTY(sc, scp->index);
+ if (tp->t_state & TS_ISOPEN)
+ scstart(tp);
+#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:
+#if NSPLASH > 0
+ /* 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 /* NSPLASH */
+ break;
+
+ case RBT:
+#ifndef SC_DISABLE_REBOOT
+ shutdown_nice();
+#endif
+ break;
+
+#if NAPM > 0
+ case SUSP:
+ apm_suspend(PMST_SUSPEND);
+ break;
+ case STBY:
+ apm_suspend(PMST_STANDBY);
+ break;
+#else
+ case SUSP:
+ case STBY:
+ break;
+#endif
+
+ case DBG:
+#ifndef SC_DISABLE_DDBKEY
+#ifdef DDB
+ if (debugger)
+ break;
+ /* try to switch to the kernel console screen */
+ if (sc_console) {
+ /*
+ * TRY to make sure the screen saver is stopped,
+ * and the screen is updated before switching to
+ * the vty0.
+ */
+ scrn_timer(NULL);
+ if (!cold
+ && sc_console->sc->cur_scp->smode.mode == VT_AUTO
+ && sc_console->smode.mode == VT_AUTO)
+ switch_scr(sc_console->sc, sc_console->index);
+ }
+ Debugger("manual escape to debugger");
+#else
+ printf("No debugger in kernel\n");
+#endif
+#else /* SC_DISABLE_DDBKEY */
+ /* do nothing */
+#endif /* SC_DISABLE_DDBKEY */
+ 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 = VIRTUAL_TTY(sc, sc->first_vty + i);
+ if (tp && tp->t_state & TS_ISOPEN) {
+ 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 = VIRTUAL_TTY(sc, sc->first_vty + i);
+ if (tp && tp->t_state & TS_ISOPEN) {
+ switch_scr(scp->sc, sc->first_vty + i);
+ break;
+ }
+ }
+ break;
+
+ default:
+ if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
+ 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;
+}
+
+int
+scmmap(dev_t dev, vm_offset_t offset, int nprot)
+{
+ scr_stat *scp;
+
+ if (SC_VTY(dev) == SC_MOUSE)
+ return -1;
+ scp = SC_STAT(dev);
+ if (scp != scp->sc->cur_scp)
+ return -1;
+ return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
+}
+
+/*
+ * Calculate hardware attributes word using logical attributes mask and
+ * hardware colors
+ */
+
+static int
+mask2attr(struct term_stat *term)
+{
+ int attr, mask = term->attr_mask;
+
+ if (mask & REVERSE_ATTR) {
+ attr = ((mask & FOREGROUND_CHANGED) ?
+ ((term->cur_color & 0xF000) >> 4) :
+ (term->rev_color & 0x0F00)) |
+ ((mask & BACKGROUND_CHANGED) ?
+ ((term->cur_color & 0x0F00) << 4) :
+ (term->rev_color & 0xF000));
+ } else
+ attr = term->cur_color;
+
+ /* XXX: underline mapping for Hercules adapter can be better */
+ if (mask & (BOLD_ATTR | UNDERLINE_ATTR))
+ attr ^= 0x0800;
+ if (mask & BLINK_ATTR)
+ attr ^= 0x8000;
+
+ return attr;
+}
+
+static int
+save_kbd_state(scr_stat *scp)
+{
+ int state;
+ int error;
+
+ error = kbd_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 = kbd_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 = kbd_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 = kbd_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 ((*vidsw[scp->sc->adapter]->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 */
+ (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
+ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
+ (void *)scp->sc->adp->va_window, FALSE);
+
+#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)
+ copy_font(scp, LOAD, 8, scp->sc->font_8);
+ } else if (scp->font_size >= 16) {
+ if (scp->sc->fonts_loaded & FONT_16)
+ copy_font(scp, LOAD, 16, scp->sc->font_16);
+ } else {
+ if (scp->sc->fonts_loaded & FONT_14)
+ copy_font(scp, LOAD, 14, scp->sc->font_14);
+ }
+ /*
+ * 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
+ */
+ (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, 0);
+ }
+ mark_all(scp);
+ }
+#endif /* !SC_NO_FONT_LOADING */
+
+ set_border(scp, scp->border);
+ sc_set_cursor_image(scp);
+
+ return 0;
+}
+
+void
+set_border(scr_stat *scp, int color)
+{
+ ++scp->sc->videoio_in_progress;
+ (*scp->rndr->draw_border)(scp, color);
+ --scp->sc->videoio_in_progress;
+}
+
+#ifndef SC_NO_FONT_LOADING
+void
+copy_font(scr_stat *scp, int operation, int font_size, u_char *buf)
+{
+ /*
+ * 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
+ */
+ scp->sc->font_loading_in_progress = TRUE;
+ if (operation == LOAD) {
+ (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, font_size,
+ buf, 0, 256);
+ } else if (operation == SAVE) {
+ (*vidsw[scp->sc->adapter]->save_font)(scp->sc->adp, 0, font_size,
+ buf, 0, 256);
+ }
+ scp->sc->font_loading_in_progress = FALSE;
+}
+#endif /* !SC_NO_FONT_LOADING */
+
+#ifndef SC_NO_SYSMOUSE
+struct tty
+*sc_get_mouse_tty(void)
+{
+ return sc_mouse_tty;
+}
+#endif /* !SC_NO_SYSMOUSE */
+
+#ifndef SC_NO_CUTPASTE
+void
+sc_paste(scr_stat *scp, u_char *p, int count)
+{
+ struct tty *tp;
+ u_char *rmap;
+
+ if (scp->status & MOUSE_VISIBLE) {
+ tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
+ if (!(tp->t_state & TS_ISOPEN))
+ return;
+ rmap = scp->sc->scr_rmap;
+ for (; count > 0; --count)
+ (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
+ }
+}
+#endif /* SC_NO_CUTPASTE */
+
+static void
+do_bell(scr_stat *scp, int pitch, int duration)
+{
+ if (cold || shutdown_in_progress)
+ 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 (scp != scp->sc->cur_scp)
+ pitch *= 2;
+ sysbeep(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 = VIRTUAL_TTY(scp->sc, scp->index);
+ if (tp->t_state & TS_ISOPEN)
+ scstart(tp);
+ if (scp->sc->delayed_next_scr)
+ 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);
+ }
+}
+
+#endif /* NSC */
diff --git a/sys/dev/syscons/syscons.h b/sys/dev/syscons/syscons.h
new file mode 100644
index 0000000..ac38909
--- /dev/null
+++ b/sys/dev/syscons/syscons.h
@@ -0,0 +1,511 @@
+/*-
+ * 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$
+ */
+
+#ifndef _DEV_SYSCONS_SYSCONS_H_
+#define _DEV_SYSCONS_SYSCONS_H_
+
+/* machine-dependent part of the header */
+
+#ifdef PC98
+#include <pc98/pc98/sc_machdep.h>
+#elif defined(__i386__)
+/* nothing for the moment */
+#elif defined(__alpha__)
+/* 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
+
+#ifndef SC_DEBUG_LEVEL
+#define SC_DEBUG_LEVEL 0
+#endif
+
+#define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p
+
+#define SC_DRIVER_NAME "sc"
+#define SC_VTY(dev) minor(dev)
+#define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty])
+#define SC_STAT(dev) ((scr_stat *)(dev)->si_drv1)
+
+/* 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
+#define SWITCH_WAIT_REL 0x00080
+#define SWITCH_WAIT_ACQ 0x00100
+#define BUFFER_SAVED 0x00200
+#define CURSOR_ENABLED 0x00400
+#define MOUSE_MOVED 0x01000
+#define MOUSE_CUTTING 0x02000
+#define MOUSE_VISIBLE 0x04000
+#define GRAPHICS_MODE 0x08000
+#define PIXEL_MODE 0x10000
+#define SAVER_RUNNING 0x20000
+#define VR_CURSOR_BLINK 0x40000
+#define VR_CURSOR_ON 0x80000
+
+/* attribute flags */
+#define NORMAL_ATTR 0x00
+#define BLINK_ATTR 0x01
+#define BOLD_ATTR 0x02
+#define UNDERLINE_ATTR 0x04
+#define REVERSE_ATTR 0x08
+#define FOREGROUND_CHANGED 0x10
+#define BACKGROUND_CHANGED 0x20
+
+/* misc defines */
+#define FALSE 0
+#define TRUE 1
+#define MAX_ESC_PAR 5
+#define LOAD 1
+#define SAVE 0
+#define COL 80
+#define ROW 25
+#define CONSOLE_BUFSIZE 1024
+#define PCBURST 128
+#define FONT_NONE 1
+#define FONT_8 2
+#define FONT_14 4
+#define FONT_16 8
+
+#ifndef BELL_DURATION
+#define BELL_DURATION 5
+#define BELL_PITCH 800
+#endif
+
+/* special characters */
+#define cntlc 0x03
+#define cntld 0x04
+#define bs 0x08
+#define lf 0x0a
+#define cr 0x0d
+#define del 0x7f
+
+#define DEAD_CHAR 0x07 /* char used for cursor */
+
+/* virtual terminal buffer */
+typedef struct sc_vtb {
+ int vtb_flags;
+#define VTB_VALID (1 << 0)
+ 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;
+
+/* terminal status */
+typedef struct term_stat {
+ int esc; /* processing escape sequence */
+ int num_param; /* # of parameters to ESC */
+ int last_param; /* last parameter # */
+ int param[MAX_ESC_PAR]; /* contains ESC parameters */
+ int cur_attr; /* current hardware attr word */
+ int attr_mask; /* current logical attr mask */
+ int cur_color; /* current hardware color */
+ int std_color; /* normal hardware color */
+ int rev_color; /* reverse hardware color */
+} term_stat;
+
+/* 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)
+#define SC_BLINK_CURSOR (1 << 2)
+#define SC_CHAR_CURSOR (1 << 3)
+#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_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;
+ dev_t *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 videoio_in_progress;
+ char write_in_progress;
+ char blink_in_progress;
+
+ long scrn_time_stamp;
+
+ char cursor_base;
+ char cursor_height;
+
+ 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;
+ u_char *font_8;
+ u_char *font_14;
+ u_char *font_16;
+#endif
+
+} 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 */
+ sc_vtb_t scr;
+ sc_vtb_t vtb;
+ int xpos; /* current X position */
+ int ypos; /* current Y position */
+ int saved_xpos; /* saved X position */
+ int saved_ypos; /* saved 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 start; /* modified area start */
+ int end; /* modified area end */
+ term_stat term; /* terminal emulation stuff */
+ 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 */
+ char cursor_base; /* cursor base line # */
+ char cursor_height; /* cursor height */
+ 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_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 */
+#ifdef _SCR_MD_STAT_DECLARED_
+ scr_md_stat_t md; /* machine dependent vars */
+#endif
+} scr_stat;
+
+typedef struct default_attr {
+ int std_color; /* normal hardware color */
+ int rev_color; /* reverse hardware color */
+} default_attr;
+
+#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
+
+/* renderer function table */
+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_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;
+} sc_renderer_t;
+
+#define RENDERER(name, mode, sw) \
+ static struct sc_renderer name##_##mode##_renderer = { \
+ #name, mode, &sw \
+ }; \
+ DATA_SET(scrndr_set, name##_##mode##_renderer)
+
+extern struct linker_set scrndr_set;
+
+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)
+
+#ifndef ISMOUSEAVAIL
+#ifdef SC_ALT_MOUSE_IMAGE
+#define ISMOUSEAVAIL(af) (1)
+#else
+#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
+#endif /* SC_ALT_MOUSE_IMAGE */
+#define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
+#define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
+#endif /* ISMOUSEAVAIL */
+
+#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
+
+#define kbd_read_char(kbd, wait) \
+ (*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait))
+#define kbd_check_char(kbd) \
+ (*kbdsw[(kbd)->kb_index]->check_char)((kbd))
+#define kbd_enable(kbd) \
+ (*kbdsw[(kbd)->kb_index]->enable)((kbd))
+#define kbd_disable(kbd) \
+ (*kbdsw[(kbd)->kb_index]->disable)((kbd))
+#define kbd_lock(kbd, lockf) \
+ (*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf))
+#define kbd_ioctl(kbd, cmd, arg) \
+ (((kbd) == NULL) ? \
+ ENODEV : (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg)))
+#define kbd_clear_state(kbd) \
+ (*kbdsw[(kbd)->kb_index]->clear_state)((kbd))
+#define kbd_get_fkeystr(kbd, fkey, len) \
+ (*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len))
+#define kbd_poll(kbd, on) \
+ (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
+
+/* syscons.c */
+extern int (*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data,
+ int flag, struct proc *p);
+
+int sc_probe_unit(int unit, int flags);
+int sc_attach_unit(int unit, int flags);
+int sc_resume_unit(int unit);
+
+int set_mode(scr_stat *scp);
+
+void copy_font(scr_stat *scp, int operation, int font_size,
+ u_char *font_image);
+void set_border(scr_stat *scp, int color);
+
+void sc_touch_scrn_saver(void);
+void sc_clear_screen(scr_stat *scp);
+void sc_set_cursor_image(scr_stat *scp);
+int sc_clean_up(scr_stat *scp);
+void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
+#ifndef SC_NO_SYSMOUSE
+struct tty *sc_get_mouse_tty(void);
+#endif /* SC_NO_SYSMOUSE */
+#ifndef SC_NO_CUTPASTE
+void sc_paste(scr_stat *scp, u_char *p, int count);
+#endif /* SC_NO_CUTPASTE */
+
+/* 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,
+ int flag, struct proc *p);
+#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);
+#else
+#define sc_inside_cutmark(scp, pos) FALSE
+#define sc_remove_cutmarking(scp)
+#endif /* SC_NO_CUTPASTE */
+#ifndef SC_NO_SYSMOUSE
+void sc_mouse_set_level(int level);
+void sc_mouse_move(scr_stat *scp, int x, int y);
+int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ int flag, struct proc *p);
+#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 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);
+sc_rndr_sw_t *sc_render_match(scr_stat *scp, video_adapter_t *adp, int mode);
+int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
+ struct proc *p);
+
+/* 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);
+
+/* 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/warp/warp_saver.c b/sys/dev/syscons/warp/warp_saver.c
new file mode 100644
index 0000000..7e51407
--- /dev/null
+++ b/sys/dev/syscons/warp/warp_saver.c
@@ -0,0 +1,139 @@
+/*-
+ * 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 <machine/random.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+#include <dev/syscons/syscons.h>
+
+static u_char *vid;
+static int blanked;
+
+#define SCRW 320
+#define SCRH 200
+#define SPP 15
+#define STARS (SPP*(1+2+4+8))
+
+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(void)
+{
+ int i, j, k, n;
+
+ for (i = 1, k = 0, n = SPP*8; i < 5; i++, n /= 2)
+ for (j = 0; j < n; j++, k++) {
+ vid[star[k]] = 0;
+ star[k] += i;
+ if (star[k] > SCRW*SCRH)
+ star[k] -= SCRW*SCRH;
+ vid[star[k]] = i;
+ }
+}
+
+static int
+warp_saver(video_adapter_t *adp, int blank)
+{
+ int pl;
+
+ if (blank) {
+ /* switch to graphics mode */
+ if (blanked <= 0) {
+ pl = splhigh();
+ set_video_mode(adp, M_VGA_CG320);
+ load_palette(adp, warp_pal);
+#if 0 /* XXX conflict */
+ set_border(adp, 0);
+#endif
+ blanked++;
+ vid = (u_char *)adp->va_window;
+ splx(pl);
+ bzero(vid, SCRW*SCRH);
+ }
+
+ /* update display */
+ warp_update();
+
+ } else {
+ blanked = 0;
+ }
+ return 0;
+}
+
+static int
+warp_init(video_adapter_t *adp)
+{
+ video_info_t info;
+ int i;
+
+ /* check that the console is capable of running in 320x200x256 */
+ if (get_mode_info(adp, M_VGA_CG320, &info)) {
+ log(LOG_NOTICE, "warp_saver: the console does not support M_VGA_CG320\n");
+ return ENODEV;
+ }
+
+ /* randomize the star field */
+ for (i = 0; i < STARS; i++) {
+ star[i] = random() % (SCRW*SCRH);
+ }
+
+ blanked = 0;
+
+ return 0;
+}
+
+static int
+warp_term(video_adapter_t *adp)
+{
+ return 0;
+}
+
+static scrn_saver_t warp_module = {
+ "warp_saver", warp_init, warp_term, warp_saver, NULL,
+};
+
+SAVER_MODULE(warp_saver, warp_module);
OpenPOWER on IntegriCloud