Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 May 2001 01:07:20 +0100
From:      Nik Clayton <nik@freebsd.org>
To:        Nik Clayton <nik@freebsd.org>
Cc:        arch@freebsd.org
Subject:   Re: [PATCH] syscons ioctl() to grab text mode buffer
Message-ID:  <20010518010720.A8037@catkin.nothing-going-on.org>
In-Reply-To: <20010517121902.A3047@catkin.nothing-going-on.org>; from nik@freebsd.org on Thu, May 17, 2001 at 12:19:02PM %2B0100
References:  <20010517121902.A3047@catkin.nothing-going-on.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--oLBj+sq0vYjzfsbl
Content-Type: multipart/mixed; boundary="yrj/dFKFPuw6o+aM"
Content-Disposition: inline


--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, May 17, 2001 at 12:19:02PM +0100, Nik Clayton wrote:
> The second, scrshot.c uses the ioctl to dump the contents of the video
> memory to stdout. =20

Attached is an updated version, with Ruslan's patches.  I've also

 (a) Dug through the petrification layer of my mail archives, and=20
     discovered that a chunk of the code was originally written by Joel
     Holveck, who is now credited appropriately.

 (b) Knocked together a man page.

 (c) Tweaked the output format.

     Byte 1	Output format version (currently 1)
     Byte 2	Width of the display at snapshot time, in characters
     Byte 3	Depth of the display at snapshot time, in characters
     Byte 4+	Snapshot data

     Hopefully this should allow a little bit of future proofing, should
     more information need to included in the future (e.g., the name of
     font that was loaded at the time, that sort of thing).

     Any comments about better ways to do this, and or other information
     that should be part of the file format are appreciated.

N
--=20
FreeBSD: The Power to Serve             http://www.freebsd.org/
FreeBSD Documentation Project           http://www.freebsd.org/docproj/

          --- 15B8 3FFC DDB4 34B0 AA5F  94B7 93A8 0764 2C37 E375 ---

--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="scrshot.c"
Content-Transfer-Encoding: quoted-printable

/*-
 * Copyright (c) 2001 Joel Holveck and Nik Clayton
 * 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$
 */

#include <sys/types.h>
#include <sys/consio.h>
#include <sys/ioctl.h>
#include <sys/uio.h>

#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define	 VERSION 	1	/* File format version */

/*
 * Given the path to a syscons terminal (e.g., "/dev/ttyv0"), tries to
 * snapshot the video memory of that terminal, using the CONS_SCRSHOT
 * ioctl, and writes the results to stdout.
 */
int
main(int argc, char *argv[])
{
	int fd;
	scrshot_t shot;
	vid_info_t info;

	if (argc !=3D 2)
		errx(1, "improper # of args");

	fd =3D open(argv[1], O_RDWR);
	if (fd < 0)
		err(1, "%s", argv[1]);
=09
	info.size =3D sizeof(info);
	if (ioctl(fd, CONS_GETINFO, &info) =3D=3D -1)
		err(1, "ioctl(CONS_GETINFO)");
=09
	shot.buf =3D malloc(info.mv_csz * info.mv_rsz * sizeof(u_int16_t));
	if (shot.buf =3D=3D NULL)
		err(1, "couldn't allocate shot space");
=09
	shot.xsize =3D info.mv_csz;
	shot.ysize =3D info.mv_rsz;
	if (ioctl(fd, CONS_SCRSHOT, &shot) =3D=3D -1)
		err(1, "ioctl(CONS_SCRSHOT)");

	printf("%c%c%c", VERSION, shot.xsize, shot.ysize);
=09
	(void)write(STDOUT_FILENO, shot.buf,
	    shot.xsize * shot.ysize * sizeof(u_int16_t));

	exit(0);
}

--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="scrshot.1"

.\" Copyright (c) 2001 Nik Clayton
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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$
.\"
.Dd May 17, 2001
.Dt SCRSHOT 1
.Os
.Sh NAME
.Nm scrshot
.Nd capture the contents of a syscons terminal
.Sh SYNOPSIS
.Nm
.Ar device
.Sh DESCRIPTION
The
.Nm
utility uses the
.Xr syscons 4
.Li CONS_SCRSHOT
ioctl to capture the current contents of the terminal device given as the
first argument.
.Nm
writes version and additional information to the standard output, followed by
the contents of the terminal device.
.Sh IMPLEMENTATION NOTES
PC video memory is typically arranged in two byte tuples, one per character
position.  In each tuple, the first byte will be the character code, and the
second byte is the character's colour attribute.
.Pp
The colour attribute byte is further broken down in to the low nybble, which
specifies which of 16 different foreground colours is active, and the high
nybble, which specifies which of 16 different background colours is active.
.Pp
.Bl -hang -offset indent -compact
.It 0
Black
.It 1
Blue
.It 2
Green
.It 3
Cyan
.It 4
Red
.It 5
Magenta
.It 6
Brown
.It 7
White
.It 8
Grey
.It 9
Light Blue
.It 10
Light Green
.It 11
Light Cyan
.It 12
Light Red
.It 13
Light Magenta
.It 14
Yellow
.It 15
White
.El
.Pp
It can be seen that the last 8 colours are brighter versions of the first 8.
.Pp
For example, the two bytes
.Bd -literal -offset indent
65 158
.Ed
.Pp
specify an uppercase A (character code 65), in yellow (low nybble 15) on a
light blue background (high nybble 9).
.Pp
The
.Nm
output contains a small header which includes additional information which may
be useful to utilities processing the output.
.Pp
The first byte of the header contains the version number.  Subsequent bytes
depend on the version number.
.Bl -column "Version " "4 and up" -offset indent
.It Sy Version Ta Sy Byte Ta Sy Meaning
.It 1 Ta 2 Ta Terminal width, in characters
.It Ta 3 Ta Terminal depth, in characters
.It Ta 4 and up Ta The snapshot data
.El
.Sh RETURN VALUES
The
.Nm
utility exits 0 on success or >0 if an error occurred.
.Sh EXAMPLES
The command:
.Bd -literal -offset indent
.Ic scrshot /dev/ttyv0 > shot.scr
.Ed
.Pp
will capture the contents of the first virtual terminal, and redirect the
output to the
.Li shot.scr
file.
.Sh SEE ALSO
.Xr syscons 4 ,
.Xr ascii 7 ,
.Xr watch 8 .
.Pp
The various
.Li shot2*
utilities in the
.Li textproc
category of the ports collection.
.Sh HISTORY
A
.Nm
utility appeared in
.Fx 5.0
and was backported to
.Fx 4.4 .
.Sh AUTHORS
.An Joel Holveck Aq joelh@gnu.org
and
.An Nik Clayton Aq nik@FreeBSD.org
--yrj/dFKFPuw6o+aM--

--oLBj+sq0vYjzfsbl
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.5 (FreeBSD)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjsEZ7cACgkQk6gHZCw343WWSQCgg5nwmQR5owsizubXvYUgo28W
h/UAoIt7CKWdcjkmNu0JkemFNn9UP30a
=QEEw
-----END PGP SIGNATURE-----

--oLBj+sq0vYjzfsbl--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010518010720.A8037>