1994-08-17 09:00:13 +00:00
|
|
|
|
/*-
|
1996-06-21 07:20:13 +00:00
|
|
|
|
* Copyright (c) 1994-1996 S<EFBFBD>ren Schmidt
|
1994-08-17 09:00:13 +00:00
|
|
|
|
* 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
|
1995-01-28 22:18:05 +00:00
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
|
* in this position and unchanged.
|
1994-08-17 09:00:13 +00:00
|
|
|
|
* 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
|
2002-06-02 20:05:59 +00:00
|
|
|
|
* derived from this software without specific prior written permission
|
1994-08-17 09:00:13 +00:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
1997-10-27 07:52:10 +00:00
|
|
|
|
#ifndef lint
|
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
|
"$FreeBSD$";
|
1997-10-27 07:52:10 +00:00
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
1994-08-17 09:00:13 +00:00
|
|
|
|
#include <ctype.h>
|
1997-10-27 07:52:10 +00:00
|
|
|
|
#include <err.h>
|
2000-01-12 12:30:33 +00:00
|
|
|
|
#include <limits.h>
|
1994-08-17 09:00:13 +00:00
|
|
|
|
#include <stdio.h>
|
1997-03-07 01:34:47 +00:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
1997-10-27 07:52:10 +00:00
|
|
|
|
#include <unistd.h>
|
2000-10-08 21:34:00 +00:00
|
|
|
|
#include <sys/fbio.h>
|
|
|
|
|
#include <sys/consio.h>
|
1994-08-17 09:00:13 +00:00
|
|
|
|
#include <sys/errno.h>
|
2001-04-09 17:24:29 +00:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
1994-08-17 09:00:13 +00:00
|
|
|
|
#include "path.h"
|
1997-03-07 01:34:47 +00:00
|
|
|
|
#include "decode.h"
|
1994-08-17 09:00:13 +00:00
|
|
|
|
|
2001-01-25 16:53:22 +00:00
|
|
|
|
#define _VESA_800x600_DFL_COLS 80
|
|
|
|
|
#define _VESA_800x600_DFL_ROWS 25
|
|
|
|
|
#define _VESA_800x600_DFL_FNSZ 16
|
|
|
|
|
|
2002-08-19 16:33:23 +00:00
|
|
|
|
/* Screen dump modes */
|
|
|
|
|
#define DUMP_FMT_RAW 1
|
|
|
|
|
#define DUMP_FMT_TXT 2
|
|
|
|
|
/* Screen dump options */
|
|
|
|
|
#define DUMP_FBF 0
|
|
|
|
|
#define DUMP_ALL 1
|
|
|
|
|
/* Screen dump file format revision */
|
2001-05-19 06:47:36 +00:00
|
|
|
|
#define DUMP_FMT_REV 1
|
|
|
|
|
|
1994-08-17 09:00:13 +00:00
|
|
|
|
char legal_colors[16][16] = {
|
|
|
|
|
"black", "blue", "green", "cyan",
|
|
|
|
|
"red", "magenta", "brown", "white",
|
|
|
|
|
"grey", "lightblue", "lightgreen", "lightcyan",
|
|
|
|
|
"lightred", "lightmagenta", "yellow", "lightwhite"
|
1995-02-22 13:48:07 +00:00
|
|
|
|
};
|
1994-08-17 09:00:13 +00:00
|
|
|
|
int hex = 0;
|
1995-01-30 21:44:07 +00:00
|
|
|
|
int number;
|
2001-01-25 16:53:22 +00:00
|
|
|
|
int vesa_cols = _VESA_800x600_DFL_COLS;
|
|
|
|
|
int vesa_rows = _VESA_800x600_DFL_ROWS;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
char letter;
|
|
|
|
|
struct vid_info info;
|
|
|
|
|
|
|
|
|
|
|
1997-10-27 07:52:10 +00:00
|
|
|
|
static void
|
2005-01-13 03:59:44 +00:00
|
|
|
|
usage(void)
|
1995-02-22 13:48:07 +00:00
|
|
|
|
{
|
2002-07-10 03:37:42 +00:00
|
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
2002-08-19 16:33:23 +00:00
|
|
|
|
"usage: vidcontrol [-CdHLPpx] [-b color] [-c appearance] [-f [size] file]",
|
2001-05-28 11:05:28 +00:00
|
|
|
|
" [-g geometry] [-h size] [-i adapter | mode] [-l screen_map]",
|
2002-07-10 03:37:42 +00:00
|
|
|
|
" [-M char] [-m on | off] [-r foreground background]",
|
|
|
|
|
" [-S on | off] [-s number] [-t N | off] [mode]",
|
|
|
|
|
" [foreground [background]] [show]");
|
1997-10-27 07:52:10 +00:00
|
|
|
|
exit(1);
|
1995-02-22 13:48:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static char *
|
2001-04-09 17:24:29 +00:00
|
|
|
|
nextarg(int ac, char **av, int *indp, int oc, int strict)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
|
|
|
|
if (*indp < ac)
|
|
|
|
|
return(av[(*indp)++]);
|
2001-04-09 17:24:29 +00:00
|
|
|
|
if (strict != 0)
|
|
|
|
|
errx(1, "option requires two arguments -- %c", oc);
|
|
|
|
|
return(NULL);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static FILE *
|
|
|
|
|
openguess(const char *a[], const char *b[], const char *c[], const char *d[], char **name)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
2002-03-16 23:35:51 +00:00
|
|
|
|
FILE *f;
|
|
|
|
|
int i, j, k, l;
|
|
|
|
|
|
|
|
|
|
for (i = 0; a[i] != NULL; i++) {
|
|
|
|
|
for (j = 0; b[j] != NULL; j++) {
|
|
|
|
|
for (k = 0; c[k] != NULL; k++) {
|
|
|
|
|
for (l = 0; d[l] != NULL; l++) {
|
|
|
|
|
asprintf(name, "%s%s%s%s", a[i], b[j],
|
|
|
|
|
c[k], d[l]);
|
|
|
|
|
f = fopen(*name, "r");
|
|
|
|
|
if (f != NULL)
|
|
|
|
|
return (f);
|
|
|
|
|
free(*name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
2002-03-16 23:35:51 +00:00
|
|
|
|
return (NULL);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
load_scrnmap(const char *filename)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
2002-03-16 23:35:51 +00:00
|
|
|
|
FILE *fd;
|
|
|
|
|
int size;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
char *name;
|
|
|
|
|
scrmap_t scrnmap;
|
2005-01-13 03:59:44 +00:00
|
|
|
|
const char *a[] = {"", SCRNMAP_PATH, NULL};
|
|
|
|
|
const char *b[] = {filename, NULL};
|
|
|
|
|
const char *c[] = {"", ".scm", NULL};
|
|
|
|
|
const char *d[] = {"", NULL};
|
2002-03-16 23:35:51 +00:00
|
|
|
|
|
|
|
|
|
fd = openguess(a, b, c, d, &name);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
if (fd == NULL) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("screenmap file not found");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
size = sizeof(scrnmap);
|
2001-04-09 17:24:29 +00:00
|
|
|
|
if (decode(fd, (char *)&scrnmap, size) != size) {
|
1994-08-17 09:00:13 +00:00
|
|
|
|
rewind(fd);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (fread(&scrnmap, 1, size, fd) != (unsigned)size) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warnx("bad screenmap file");
|
1997-03-07 01:34:47 +00:00
|
|
|
|
fclose(fd);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ioctl(0, PIO_SCRNMAP, &scrnmap) < 0)
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("can't load screenmap");
|
1997-03-07 01:34:47 +00:00
|
|
|
|
fclose(fd);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
load_default_scrnmap(void)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
|
|
|
|
scrmap_t scrnmap;
|
1995-02-22 13:48:07 +00:00
|
|
|
|
int i;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
|
|
|
|
|
for (i=0; i<256; i++)
|
|
|
|
|
*((char*)&scrnmap + i) = i;
|
|
|
|
|
if (ioctl(0, PIO_SCRNMAP, &scrnmap) < 0)
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("can't load default screenmap");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
print_scrnmap(void)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned char map[256];
|
2005-01-13 03:59:44 +00:00
|
|
|
|
size_t i;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
|
|
|
|
|
if (ioctl(0, GIO_SCRNMAP, &map) < 0) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("getting screenmap");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (i=0; i<sizeof(map); i++) {
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (i != 0 && i % 16 == 0)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
|
if (hex)
|
1995-05-30 03:57:47 +00:00
|
|
|
|
fprintf(stdout, " %02x", map[i]);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
else
|
|
|
|
|
fprintf(stdout, " %03d", map[i]);
|
|
|
|
|
}
|
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static int
|
2001-04-09 17:24:29 +00:00
|
|
|
|
fsize(FILE *file)
|
|
|
|
|
{
|
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
|
|
if (fstat(fileno(file), &sb) == 0)
|
|
|
|
|
return sb.st_size;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define DATASIZE(x) ((x).w * (x).h * 256 / 8)
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
load_font(const char *type, const char *filename)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
2002-03-16 23:35:51 +00:00
|
|
|
|
FILE *fd;
|
2001-04-09 17:24:29 +00:00
|
|
|
|
int h, i, size, w;
|
|
|
|
|
unsigned long io = 0; /* silence stupid gcc(1) in the Wall mode */
|
2002-03-16 23:35:51 +00:00
|
|
|
|
char *name, *fontmap, size_sufx[6];
|
2005-01-13 03:59:44 +00:00
|
|
|
|
const char *a[] = {"", FONT_PATH, NULL};
|
|
|
|
|
const char *b[] = {filename, NULL};
|
|
|
|
|
const char *c[] = {"", size_sufx, NULL};
|
|
|
|
|
const char *d[] = {"", ".fnt", NULL};
|
|
|
|
|
vid_info_t _info;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
|
2001-04-09 17:24:29 +00:00
|
|
|
|
struct sizeinfo {
|
|
|
|
|
int w;
|
|
|
|
|
int h;
|
|
|
|
|
unsigned long io;
|
|
|
|
|
} sizes[] = {{8, 16, PIO_FONT8x16},
|
|
|
|
|
{8, 14, PIO_FONT8x14},
|
|
|
|
|
{8, 8, PIO_FONT8x8},
|
|
|
|
|
{0, 0, 0}};
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
_info.size = sizeof(_info);
|
|
|
|
|
if (ioctl(0, CONS_GETINFO, &_info) == -1) {
|
2002-03-16 23:35:51 +00:00
|
|
|
|
warn("failed to obtain current video mode parameters");
|
|
|
|
|
return;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
2005-01-13 03:59:44 +00:00
|
|
|
|
snprintf(size_sufx, sizeof(size_sufx), "-8x%d", _info.font_size);
|
2002-03-16 23:35:51 +00:00
|
|
|
|
fd = openguess(a, b, c, d, &name);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
if (fd == NULL) {
|
2001-04-09 17:24:29 +00:00
|
|
|
|
warn("%s: can't load font file", filename);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2001-04-09 17:24:29 +00:00
|
|
|
|
if (type != NULL) {
|
|
|
|
|
size = 0;
|
|
|
|
|
if (sscanf(type, "%dx%d", &w, &h) == 2)
|
|
|
|
|
for (i = 0; sizes[i].w != 0; i++)
|
|
|
|
|
if (sizes[i].w == w && sizes[i].h == h) {
|
|
|
|
|
size = DATASIZE(sizes[i]);
|
|
|
|
|
io = sizes[i].io;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
|
warnx("%s: bad font size specification", type);
|
|
|
|
|
fclose(fd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Apply heuristics */
|
|
|
|
|
int j;
|
|
|
|
|
int dsize[2];
|
|
|
|
|
|
|
|
|
|
size = DATASIZE(sizes[0]);
|
|
|
|
|
fontmap = (char*) malloc(size);
|
|
|
|
|
dsize[0] = decode(fd, fontmap, size);
|
|
|
|
|
dsize[1] = fsize(fd);
|
|
|
|
|
free(fontmap);
|
|
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
|
for (j = 0; j < 2; j++)
|
|
|
|
|
for (i = 0; sizes[i].w != 0; i++)
|
|
|
|
|
if (DATASIZE(sizes[i]) == dsize[j]) {
|
|
|
|
|
size = dsize[j];
|
|
|
|
|
io = sizes[i].io;
|
|
|
|
|
j = 2; /* XXX */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
|
warnx("%s: can't guess font size", filename);
|
|
|
|
|
fclose(fd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
rewind(fd);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
2001-04-09 17:24:29 +00:00
|
|
|
|
|
1994-08-17 09:00:13 +00:00
|
|
|
|
fontmap = (char*) malloc(size);
|
2001-04-09 17:24:29 +00:00
|
|
|
|
if (decode(fd, fontmap, size) != size) {
|
1994-08-17 09:00:13 +00:00
|
|
|
|
rewind(fd);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (fsize(fd) != size || fread(fontmap, 1, size, fd) != (unsigned)size) {
|
2001-04-09 17:24:29 +00:00
|
|
|
|
warnx("%s: bad font file", filename);
|
1997-03-07 01:34:47 +00:00
|
|
|
|
fclose(fd);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
free(fontmap);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ioctl(0, io, fontmap) < 0)
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("can't load font");
|
1997-03-07 01:34:47 +00:00
|
|
|
|
fclose(fd);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
free(fontmap);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1994-08-17 09:00:13 +00:00
|
|
|
|
set_screensaver_timeout(char *arg)
|
|
|
|
|
{
|
|
|
|
|
int nsec;
|
|
|
|
|
|
|
|
|
|
if (!strcmp(arg, "off"))
|
|
|
|
|
nsec = 0;
|
|
|
|
|
else {
|
|
|
|
|
nsec = atoi(arg);
|
|
|
|
|
if ((*arg == '\0') || (nsec < 1)) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warnx("argument must be a positive number");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ioctl(0, CONS_BLANKTIME, &nsec) == -1)
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("setting screensaver period");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1995-01-12 11:47:05 +00:00
|
|
|
|
set_cursor_type(char *appearence)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
1995-01-12 11:47:05 +00:00
|
|
|
|
int type;
|
|
|
|
|
|
1995-02-07 11:56:21 +00:00
|
|
|
|
if (!strcmp(appearence, "normal"))
|
1995-01-12 11:47:05 +00:00
|
|
|
|
type = 0;
|
1995-02-07 11:56:21 +00:00
|
|
|
|
else if (!strcmp(appearence, "blink"))
|
|
|
|
|
type = 1;
|
|
|
|
|
else if (!strcmp(appearence, "destructive"))
|
|
|
|
|
type = 3;
|
1995-01-12 11:47:05 +00:00
|
|
|
|
else {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warnx("argument to -c must be normal, blink or destructive");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1995-01-12 11:47:05 +00:00
|
|
|
|
ioctl(0, CONS_CURSORTYPE, &type);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static int
|
|
|
|
|
video_mode(int argc, char **argv, int *_index)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
1998-09-23 10:00:15 +00:00
|
|
|
|
static struct {
|
2005-01-13 03:59:44 +00:00
|
|
|
|
const char *name;
|
1998-09-23 10:00:15 +00:00
|
|
|
|
unsigned long mode;
|
|
|
|
|
} modes[] = {
|
|
|
|
|
{ "80x25", SW_TEXT_80x25 },
|
|
|
|
|
{ "80x30", SW_TEXT_80x30 },
|
|
|
|
|
{ "80x43", SW_TEXT_80x43 },
|
|
|
|
|
{ "80x50", SW_TEXT_80x50 },
|
|
|
|
|
{ "80x60", SW_TEXT_80x60 },
|
|
|
|
|
{ "132x25", SW_TEXT_132x25 },
|
|
|
|
|
{ "132x30", SW_TEXT_132x30 },
|
|
|
|
|
{ "132x43", SW_TEXT_132x43 },
|
|
|
|
|
{ "132x50", SW_TEXT_132x50 },
|
|
|
|
|
{ "132x60", SW_TEXT_132x60 },
|
|
|
|
|
{ "VGA_40x25", SW_VGA_C40x25 },
|
|
|
|
|
{ "VGA_80x25", SW_VGA_C80x25 },
|
|
|
|
|
{ "VGA_80x30", SW_VGA_C80x30 },
|
|
|
|
|
{ "VGA_80x50", SW_VGA_C80x50 },
|
|
|
|
|
{ "VGA_80x60", SW_VGA_C80x60 },
|
1999-06-22 14:15:46 +00:00
|
|
|
|
#ifdef SW_VGA_C90x25
|
|
|
|
|
{ "VGA_90x25", SW_VGA_C90x25 },
|
|
|
|
|
{ "VGA_90x30", SW_VGA_C90x30 },
|
|
|
|
|
{ "VGA_90x43", SW_VGA_C90x43 },
|
|
|
|
|
{ "VGA_90x50", SW_VGA_C90x50 },
|
|
|
|
|
{ "VGA_90x60", SW_VGA_C90x60 },
|
|
|
|
|
#endif
|
1998-09-23 10:00:15 +00:00
|
|
|
|
{ "VGA_320x200", SW_VGA_CG320 },
|
|
|
|
|
{ "EGA_80x25", SW_ENH_C80x25 },
|
|
|
|
|
{ "EGA_80x43", SW_ENH_C80x43 },
|
|
|
|
|
{ "VESA_132x25", SW_VESA_C132x25 },
|
|
|
|
|
{ "VESA_132x43", SW_VESA_C132x43 },
|
|
|
|
|
{ "VESA_132x50", SW_VESA_C132x50 },
|
|
|
|
|
{ "VESA_132x60", SW_VESA_C132x60 },
|
|
|
|
|
{ "VESA_800x600", SW_VESA_800x600 },
|
2005-01-13 03:59:44 +00:00
|
|
|
|
{ NULL, 0 },
|
1998-09-23 10:00:15 +00:00
|
|
|
|
};
|
1999-01-12 23:05:45 +00:00
|
|
|
|
unsigned long mode = 0;
|
1999-06-22 14:15:46 +00:00
|
|
|
|
int cur_mode;
|
|
|
|
|
int ioerr;
|
1998-09-15 18:16:39 +00:00
|
|
|
|
int size[3];
|
1998-09-23 10:00:15 +00:00
|
|
|
|
int i;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
|
1999-06-22 14:15:46 +00:00
|
|
|
|
if (ioctl(0, CONS_GET, &cur_mode) < 0)
|
|
|
|
|
err(1, "cannot get the current video mode");
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (*_index < argc) {
|
1998-09-23 10:00:15 +00:00
|
|
|
|
for (i = 0; modes[i].name != NULL; ++i) {
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (!strcmp(argv[*_index], modes[i].name)) {
|
1998-09-23 10:00:15 +00:00
|
|
|
|
mode = modes[i].mode;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (modes[i].name == NULL)
|
2003-09-18 16:20:32 +00:00
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
if (ioctl(0, mode, NULL) < 0) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("cannot set videomode");
|
2003-09-18 16:20:32 +00:00
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
1998-09-15 18:16:39 +00:00
|
|
|
|
if (mode == SW_VESA_800x600) {
|
2001-01-25 16:53:22 +00:00
|
|
|
|
/* columns */
|
|
|
|
|
if ((vesa_cols * 8 > 800) || (vesa_cols <= 0)) {
|
|
|
|
|
warnx("incorrect number of columns: %d",
|
|
|
|
|
vesa_cols);
|
|
|
|
|
size[0] = _VESA_800x600_DFL_COLS;
|
|
|
|
|
} else {
|
|
|
|
|
size[0] = vesa_cols;
|
|
|
|
|
}
|
|
|
|
|
/* rows */
|
|
|
|
|
if ((vesa_rows * _VESA_800x600_DFL_FNSZ > 600) ||
|
|
|
|
|
(vesa_rows <=0)) {
|
|
|
|
|
warnx("incorrect number of rows: %d",
|
|
|
|
|
vesa_rows);
|
|
|
|
|
size[1] = _VESA_800x600_DFL_ROWS;
|
|
|
|
|
} else {
|
|
|
|
|
size[1] = vesa_rows;
|
|
|
|
|
}
|
|
|
|
|
/* font size */
|
|
|
|
|
size[2] = _VESA_800x600_DFL_FNSZ;
|
1999-06-22 14:15:46 +00:00
|
|
|
|
if (ioctl(0, KDRASTER, size)) {
|
|
|
|
|
ioerr = errno;
|
|
|
|
|
if (cur_mode >= M_VESA_BASE)
|
2001-07-22 13:30:32 +00:00
|
|
|
|
ioctl(0,
|
|
|
|
|
_IO('V', cur_mode - M_VESA_BASE),
|
|
|
|
|
NULL);
|
1999-06-22 14:15:46 +00:00
|
|
|
|
else
|
|
|
|
|
ioctl(0, _IO('S', cur_mode), NULL);
|
|
|
|
|
warnc(ioerr, "cannot activate raster display");
|
2003-09-18 16:20:32 +00:00
|
|
|
|
return EXIT_FAILURE;
|
1999-06-22 14:15:46 +00:00
|
|
|
|
}
|
1998-09-15 18:16:39 +00:00
|
|
|
|
}
|
2005-01-13 03:59:44 +00:00
|
|
|
|
(*_index)++;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
2003-09-18 16:20:32 +00:00
|
|
|
|
return EXIT_SUCCESS;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static int
|
1994-08-17 09:00:13 +00:00
|
|
|
|
get_color_number(char *color)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
|
if (!strcmp(color, legal_colors[i]))
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
set_normal_colors(int argc, char **argv, int *_index)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
|
|
|
|
int color;
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (*_index < argc && (color = get_color_number(argv[*_index])) != -1) {
|
|
|
|
|
(*_index)++;
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stderr, "\033[=%dF", color);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (*_index < argc
|
|
|
|
|
&& (color = get_color_number(argv[*_index])) != -1
|
1994-08-17 09:00:13 +00:00
|
|
|
|
&& color < 8) {
|
2005-01-13 03:59:44 +00:00
|
|
|
|
(*_index)++;
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stderr, "\033[=%dG", color);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
set_reverse_colors(int argc, char **argv, int *_index)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
|
|
|
|
int color;
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if ((color = get_color_number(argv[*(_index)-1])) != -1) {
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stderr, "\033[=%dH", color);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (*_index < argc
|
|
|
|
|
&& (color = get_color_number(argv[*_index])) != -1
|
1994-08-17 09:00:13 +00:00
|
|
|
|
&& color < 8) {
|
2005-01-13 03:59:44 +00:00
|
|
|
|
(*_index)++;
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stderr, "\033[=%dI", color);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1997-03-07 01:34:47 +00:00
|
|
|
|
set_console(char *arg)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
if( !arg || strspn(arg,"0123456789") != strlen(arg)) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warnx("bad console number");
|
1997-03-07 01:34:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = atoi(arg);
|
1999-09-19 08:04:07 +00:00
|
|
|
|
if (n < 1 || n > 16) {
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warnx("console number out of range");
|
1999-01-12 23:05:45 +00:00
|
|
|
|
} else if (ioctl(0, VT_ACTIVATE, (caddr_t) (long) n) == -1)
|
1997-10-27 07:52:10 +00:00
|
|
|
|
warn("ioctl(VT_ACTIVATE)");
|
1997-03-07 01:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1994-08-17 09:00:13 +00:00
|
|
|
|
set_border_color(char *arg)
|
|
|
|
|
{
|
|
|
|
|
int color;
|
|
|
|
|
|
|
|
|
|
if ((color = get_color_number(arg)) != -1) {
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stderr, "\033[=%dA", color);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1995-05-30 03:57:47 +00:00
|
|
|
|
usage();
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
2000-01-12 12:30:33 +00:00
|
|
|
|
set_mouse_char(char *arg)
|
|
|
|
|
{
|
|
|
|
|
struct mouse_info mouse;
|
|
|
|
|
long l;
|
|
|
|
|
|
|
|
|
|
l = strtol(arg, NULL, 0);
|
2001-04-21 13:50:32 +00:00
|
|
|
|
if ((l < 0) || (l > UCHAR_MAX - 3)) {
|
|
|
|
|
warnx("argument to -M must be 0 through %d", UCHAR_MAX - 3);
|
2000-01-12 12:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mouse.operation = MOUSE_MOUSECHAR;
|
|
|
|
|
mouse.u.mouse_char = (int)l;
|
|
|
|
|
ioctl(0, CONS_MOUSECTL, &mouse);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1996-06-21 07:20:13 +00:00
|
|
|
|
set_mouse(char *arg)
|
|
|
|
|
{
|
|
|
|
|
struct mouse_info mouse;
|
|
|
|
|
|
|
|
|
|
if (!strcmp(arg, "on"))
|
|
|
|
|
mouse.operation = MOUSE_SHOW;
|
|
|
|
|
else if (!strcmp(arg, "off"))
|
|
|
|
|
mouse.operation = MOUSE_HIDE;
|
|
|
|
|
else {
|
2002-07-10 03:39:52 +00:00
|
|
|
|
warnx("argument to -m must be either on or off");
|
1996-06-21 07:20:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ioctl(0, CONS_MOUSECTL, &mouse);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
2002-07-10 03:31:25 +00:00
|
|
|
|
set_lockswitch(char *arg)
|
|
|
|
|
{
|
|
|
|
|
int data;
|
|
|
|
|
|
|
|
|
|
if (!strcmp(arg, "off"))
|
|
|
|
|
data = 0x01;
|
|
|
|
|
else if (!strcmp(arg, "on"))
|
|
|
|
|
data = 0x02;
|
|
|
|
|
else {
|
2002-07-10 03:39:52 +00:00
|
|
|
|
warnx("argument to -S must be either on or off");
|
2002-07-10 03:31:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ioctl(0, VT_LOCKSWITCH, &data) == -1)
|
|
|
|
|
warn("ioctl(VT_LOCKSWITCH)");
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static const char
|
1998-09-15 18:16:39 +00:00
|
|
|
|
*adapter_name(int type)
|
|
|
|
|
{
|
|
|
|
|
static struct {
|
|
|
|
|
int type;
|
2005-01-13 03:59:44 +00:00
|
|
|
|
const char *name;
|
1998-09-15 18:16:39 +00:00
|
|
|
|
} names[] = {
|
|
|
|
|
{ KD_MONO, "MDA" },
|
|
|
|
|
{ KD_HERCULES, "Hercules" },
|
|
|
|
|
{ KD_CGA, "CGA" },
|
|
|
|
|
{ KD_EGA, "EGA" },
|
|
|
|
|
{ KD_VGA, "VGA" },
|
|
|
|
|
{ KD_PC98, "PC-98xx" },
|
1999-06-22 14:15:46 +00:00
|
|
|
|
{ KD_TGA, "TGA" },
|
1998-09-15 18:16:39 +00:00
|
|
|
|
{ -1, "Unknown" },
|
|
|
|
|
};
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; names[i].type != -1; ++i)
|
|
|
|
|
if (names[i].type == type)
|
|
|
|
|
break;
|
|
|
|
|
return names[i].name;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1998-09-15 18:16:39 +00:00
|
|
|
|
show_adapter_info(void)
|
|
|
|
|
{
|
1999-01-11 03:20:32 +00:00
|
|
|
|
struct video_adapter_info ad;
|
1998-09-15 18:16:39 +00:00
|
|
|
|
|
|
|
|
|
ad.va_index = 0;
|
|
|
|
|
if (ioctl(0, CONS_ADPINFO, &ad)) {
|
|
|
|
|
warn("failed to obtain adapter information");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-11 03:20:32 +00:00
|
|
|
|
printf("fb%d:\n", ad.va_index);
|
|
|
|
|
printf(" %.*s%d, type:%s%s (%d), flags:0x%x\n",
|
|
|
|
|
(int)sizeof(ad.va_name), ad.va_name, ad.va_unit,
|
1998-09-15 18:16:39 +00:00
|
|
|
|
(ad.va_flags & V_ADP_VESA) ? "VESA " : "",
|
1999-01-11 03:20:32 +00:00
|
|
|
|
adapter_name(ad.va_type), ad.va_type, ad.va_flags);
|
1998-09-15 18:16:39 +00:00
|
|
|
|
printf(" initial mode:%d, current mode:%d, BIOS mode:%d\n",
|
|
|
|
|
ad.va_initial_mode, ad.va_mode, ad.va_initial_bios_mode);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
printf(" frame buffer window:0x%zx, buffer size:0x%zx\n",
|
1999-06-22 14:15:46 +00:00
|
|
|
|
ad.va_window, ad.va_buffer_size);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
printf(" window size:0x%zx, origin:0x%x\n",
|
1999-06-22 14:15:46 +00:00
|
|
|
|
ad.va_window_size, ad.va_window_orig);
|
|
|
|
|
printf(" display start address (%d, %d), scan line width:%d\n",
|
|
|
|
|
ad.va_disp_start.x, ad.va_disp_start.y, ad.va_line_width);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
printf(" reserved:0x%zx\n", ad.va_unused0);
|
1998-09-15 18:16:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1998-09-15 18:16:39 +00:00
|
|
|
|
show_mode_info(void)
|
|
|
|
|
{
|
2005-01-13 03:59:44 +00:00
|
|
|
|
struct video_info _info;
|
1998-09-15 18:16:39 +00:00
|
|
|
|
char buf[80];
|
|
|
|
|
int mode;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
printf(" mode# flags type size "
|
|
|
|
|
"font window linear buffer\n");
|
|
|
|
|
printf("---------------------------------------"
|
|
|
|
|
"---------------------------------------\n");
|
|
|
|
|
for (mode = 0; mode < M_VESA_MODE_MAX; ++mode) {
|
2005-01-13 03:59:44 +00:00
|
|
|
|
_info.vi_mode = mode;
|
|
|
|
|
if (ioctl(0, CONS_MODEINFO, &_info))
|
1998-09-15 18:16:39 +00:00
|
|
|
|
continue;
|
2005-01-13 03:59:44 +00:00
|
|
|
|
if (_info.vi_mode != mode)
|
1999-06-22 14:15:46 +00:00
|
|
|
|
continue;
|
1998-09-15 18:16:39 +00:00
|
|
|
|
|
|
|
|
|
printf("%3d (0x%03x)", mode, mode);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
printf(" 0x%08x", _info.vi_flags);
|
|
|
|
|
if (_info.vi_flags & V_INFO_GRAPHICS) {
|
1998-09-15 18:16:39 +00:00
|
|
|
|
c = 'G';
|
|
|
|
|
snprintf(buf, sizeof(buf), "%dx%dx%d %d",
|
2005-01-13 03:59:44 +00:00
|
|
|
|
_info.vi_width, _info.vi_height,
|
|
|
|
|
_info.vi_depth, _info.vi_planes);
|
1998-09-15 18:16:39 +00:00
|
|
|
|
} else {
|
|
|
|
|
c = 'T';
|
|
|
|
|
snprintf(buf, sizeof(buf), "%dx%d",
|
2005-01-13 03:59:44 +00:00
|
|
|
|
_info.vi_width, _info.vi_height);
|
1998-09-15 18:16:39 +00:00
|
|
|
|
}
|
|
|
|
|
printf(" %c %-15s", c, buf);
|
|
|
|
|
snprintf(buf, sizeof(buf), "%dx%d",
|
2005-01-13 03:59:44 +00:00
|
|
|
|
_info.vi_cwidth, _info.vi_cheight);
|
1998-09-15 18:16:39 +00:00
|
|
|
|
printf(" %-5s", buf);
|
2005-01-13 03:59:44 +00:00
|
|
|
|
printf(" 0x%05zx %2dk %2dk",
|
|
|
|
|
_info.vi_window, (int)_info.vi_window_size/1024,
|
|
|
|
|
(int)_info.vi_window_gran/1024);
|
|
|
|
|
printf(" 0x%08zx %dk\n",
|
|
|
|
|
_info.vi_buffer, (int)_info.vi_buffer_size/1024);
|
1998-09-15 18:16:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
1998-09-15 18:16:39 +00:00
|
|
|
|
show_info(char *arg)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(arg, "adapter"))
|
|
|
|
|
show_adapter_info();
|
|
|
|
|
else if (!strcmp(arg, "mode"))
|
|
|
|
|
show_mode_info();
|
|
|
|
|
else {
|
2002-07-10 03:39:52 +00:00
|
|
|
|
warnx("argument to -i must be either adapter or mode");
|
1998-09-15 18:16:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
test_frame(void)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
{
|
2005-05-15 08:04:46 +00:00
|
|
|
|
int i, cur_mode, fore;
|
|
|
|
|
|
|
|
|
|
fore = 15;
|
|
|
|
|
|
|
|
|
|
if (ioctl(0, CONS_GET, &cur_mode) < 0)
|
|
|
|
|
err(1, "must be on a virtual console");
|
|
|
|
|
switch (cur_mode) {
|
|
|
|
|
case M_PC98_80x25:
|
|
|
|
|
case M_PC98_80x30:
|
|
|
|
|
fore = 7;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1994-08-17 09:00:13 +00:00
|
|
|
|
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stdout, "\033[=0G\n\n");
|
1994-08-17 09:00:13 +00:00
|
|
|
|
for (i=0; i<8; i++) {
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stdout, "\033[=%dF\033[=0G %2d \033[=%dF%-16s"
|
|
|
|
|
"\033[=%dF\033[=0G %2d \033[=%dF%-16s "
|
|
|
|
|
"\033[=%dF %2d \033[=%dGBACKGROUND\033[=0G\n",
|
2005-05-15 08:04:46 +00:00
|
|
|
|
fore, i, i, legal_colors[i],
|
|
|
|
|
fore, i+8, i+8, legal_colors[i+8],
|
|
|
|
|
fore, i, i);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
2005-05-15 09:43:14 +00:00
|
|
|
|
fprintf(stdout, "\033[=%dF\033[=%dG\033[=%dH\033[=%dI\n",
|
1995-05-30 03:57:47 +00:00
|
|
|
|
info.mv_norm.fore, info.mv_norm.back,
|
1994-08-17 09:00:13 +00:00
|
|
|
|
info.mv_rev.fore, info.mv_rev.back);
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-19 06:47:36 +00:00
|
|
|
|
/*
|
|
|
|
|
* Snapshot the video memory of that terminal, using the CONS_SCRSHOT
|
|
|
|
|
* ioctl, and writes the results to stdout either in the special
|
|
|
|
|
* binary format (see manual page for details), or in the plain
|
|
|
|
|
* text format.
|
|
|
|
|
*/
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
2002-08-19 16:33:23 +00:00
|
|
|
|
dump_screen(int mode, int opt)
|
2001-05-19 06:47:36 +00:00
|
|
|
|
{
|
|
|
|
|
scrshot_t shot;
|
2005-01-13 03:59:44 +00:00
|
|
|
|
vid_info_t _info;
|
2001-05-19 06:47:36 +00:00
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
_info.size = sizeof(_info);
|
|
|
|
|
if (ioctl(0, CONS_GETINFO, &_info) == -1) {
|
2001-05-19 06:47:36 +00:00
|
|
|
|
warn("failed to obtain current video mode parameters");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-19 16:33:23 +00:00
|
|
|
|
shot.x = shot.y = 0;
|
2005-01-13 03:59:44 +00:00
|
|
|
|
shot.xsize = _info.mv_csz;
|
|
|
|
|
shot.ysize = _info.mv_rsz;
|
2002-08-19 16:33:23 +00:00
|
|
|
|
if (opt == DUMP_ALL)
|
2005-01-13 03:59:44 +00:00
|
|
|
|
shot.ysize += _info.mv_hsz;
|
2002-08-19 16:33:23 +00:00
|
|
|
|
|
|
|
|
|
shot.buf = alloca(shot.xsize * shot.ysize * sizeof(u_int16_t));
|
2001-05-19 06:47:36 +00:00
|
|
|
|
if (shot.buf == NULL) {
|
|
|
|
|
warn("failed to allocate memory for dump");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ioctl(0, CONS_SCRSHOT, &shot) == -1) {
|
|
|
|
|
warn("failed to get dump of the screen");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-19 16:33:23 +00:00
|
|
|
|
if (mode == DUMP_FMT_RAW) {
|
2001-05-19 06:47:36 +00:00
|
|
|
|
printf("SCRSHOT_%c%c%c%c", DUMP_FMT_REV, 2,
|
|
|
|
|
shot.xsize, shot.ysize);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
|
|
(void)write(STDOUT_FILENO, shot.buf,
|
|
|
|
|
shot.xsize * shot.ysize * sizeof(u_int16_t));
|
|
|
|
|
} else {
|
|
|
|
|
char *line;
|
|
|
|
|
int x, y;
|
|
|
|
|
u_int16_t ch;
|
|
|
|
|
|
|
|
|
|
line = alloca(shot.xsize + 1);
|
|
|
|
|
if (line == NULL) {
|
|
|
|
|
warn("failed to allocate memory for line buffer");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < shot.ysize; y++) {
|
|
|
|
|
for (x = 0; x < shot.xsize; x++) {
|
|
|
|
|
ch = shot.buf[x + (y * shot.xsize)];
|
|
|
|
|
ch &= 0xff;
|
|
|
|
|
if (isprint(ch) == 0)
|
|
|
|
|
ch = ' ';
|
|
|
|
|
line[x] = (char)ch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Trim trailing spaces */
|
|
|
|
|
do {
|
|
|
|
|
line[x--] = '\0';
|
|
|
|
|
} while (line[x] == ' ' && x != 0);
|
|
|
|
|
|
|
|
|
|
puts(line);
|
|
|
|
|
}
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
2001-05-28 11:05:28 +00:00
|
|
|
|
set_history(char *opt)
|
|
|
|
|
{
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
size = atoi(opt);
|
|
|
|
|
if ((*opt == '\0') || size < 0) {
|
|
|
|
|
warnx("argument must be a positive number");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ioctl(0, CONS_HISTORY, &size) == -1)
|
|
|
|
|
warn("setting history buffer size");
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-13 03:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
clear_history(void)
|
2001-05-28 11:05:28 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (ioctl(0, CONS_CLRHIST) == -1)
|
|
|
|
|
warn("clear history buffer");
|
|
|
|
|
}
|
|
|
|
|
|
1997-03-07 01:34:47 +00:00
|
|
|
|
int
|
1994-08-17 09:00:13 +00:00
|
|
|
|
main(int argc, char **argv)
|
|
|
|
|
{
|
2001-04-09 17:24:29 +00:00
|
|
|
|
char *font, *type;
|
2002-08-19 16:33:23 +00:00
|
|
|
|
int dumpmod, dumpopt, opt;
|
2003-09-18 16:20:32 +00:00
|
|
|
|
int reterr;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
|
1994-08-17 09:00:13 +00:00
|
|
|
|
info.size = sizeof(info);
|
2001-05-20 12:17:31 +00:00
|
|
|
|
if (argc == 1)
|
|
|
|
|
usage();
|
|
|
|
|
/* Not reached */
|
1997-10-27 07:52:10 +00:00
|
|
|
|
if (ioctl(0, CONS_GETINFO, &info) < 0)
|
|
|
|
|
err(1, "must be on a virtual console");
|
2002-08-19 16:33:23 +00:00
|
|
|
|
dumpmod = 0;
|
|
|
|
|
dumpopt = DUMP_FBF;
|
|
|
|
|
while((opt = getopt(argc, argv, "b:Cc:df:g:h:Hi:l:LM:m:pPr:S:s:t:x")) != -1)
|
1994-08-17 09:00:13 +00:00
|
|
|
|
switch(opt) {
|
2001-05-28 11:05:28 +00:00
|
|
|
|
case 'b':
|
|
|
|
|
set_border_color(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'C':
|
|
|
|
|
clear_history();
|
|
|
|
|
break;
|
|
|
|
|
case 'c':
|
|
|
|
|
set_cursor_type(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
print_scrnmap();
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
type = optarg;
|
|
|
|
|
font = nextarg(argc, argv, &optind, 'f', 0);
|
|
|
|
|
if (font == NULL) {
|
|
|
|
|
type = NULL;
|
|
|
|
|
font = optarg;
|
|
|
|
|
}
|
|
|
|
|
load_font(type, font);
|
|
|
|
|
break;
|
|
|
|
|
case 'g':
|
|
|
|
|
if (sscanf(optarg, "%dx%d", &vesa_cols,
|
|
|
|
|
&vesa_rows) != 2) {
|
|
|
|
|
warnx("incorrect geometry: %s", optarg);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
usage();
|
2001-05-28 11:05:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
set_history(optarg);
|
|
|
|
|
break;
|
2002-08-19 16:33:23 +00:00
|
|
|
|
case 'H':
|
|
|
|
|
dumpopt = DUMP_ALL;
|
|
|
|
|
break;
|
2001-05-28 11:05:28 +00:00
|
|
|
|
case 'i':
|
|
|
|
|
show_info(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'l':
|
|
|
|
|
load_scrnmap(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'L':
|
|
|
|
|
load_default_scrnmap();
|
|
|
|
|
break;
|
|
|
|
|
case 'M':
|
|
|
|
|
set_mouse_char(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'm':
|
|
|
|
|
set_mouse(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
2002-08-19 16:33:23 +00:00
|
|
|
|
dumpmod = DUMP_FMT_RAW;
|
2001-05-28 11:05:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'P':
|
2002-08-19 16:33:23 +00:00
|
|
|
|
dumpmod = DUMP_FMT_TXT;
|
2001-05-28 11:05:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
set_reverse_colors(argc, argv, &optind);
|
|
|
|
|
break;
|
2002-07-10 03:31:25 +00:00
|
|
|
|
case 'S':
|
|
|
|
|
set_lockswitch(optarg);
|
|
|
|
|
break;
|
2001-05-28 11:05:28 +00:00
|
|
|
|
case 's':
|
|
|
|
|
set_console(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
set_screensaver_timeout(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
hex = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
usage();
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
2002-08-19 16:33:23 +00:00
|
|
|
|
if (dumpmod != 0)
|
|
|
|
|
dump_screen(dumpmod, dumpopt);
|
2003-09-18 16:20:32 +00:00
|
|
|
|
reterr = video_mode(argc, argv, &optind);
|
1997-03-07 01:34:47 +00:00
|
|
|
|
set_normal_colors(argc, argv, &optind);
|
1994-08-17 09:00:13 +00:00
|
|
|
|
if (optind < argc && !strcmp(argv[optind], "show")) {
|
|
|
|
|
test_frame();
|
|
|
|
|
optind++;
|
|
|
|
|
}
|
1997-10-27 07:52:10 +00:00
|
|
|
|
if ((optind != argc) || (argc == 1))
|
1994-08-17 09:00:13 +00:00
|
|
|
|
usage();
|
2003-09-18 16:20:32 +00:00
|
|
|
|
return reterr;
|
1994-08-17 09:00:13 +00:00
|
|
|
|
}
|
|
|
|
|
|