VGA/EGA Color/Screen Blanker
Ronald
rlb at bsts00.UUCP
Sat Nov 24 06:05:09 AEST 1990
Just wanted to post somthing that maybe of use and encourage
others to enhance for 386 UNIX on ESIX and ISC, INTEL platforms.
# This is a shell archive. Remove anything before this line.
#Unpack it by saving it in a file and typing "sh file".
#
# Wrapped by at bsts00 on Fri Nov 23 13:59:53 EST 1990.
#
#This archive contains:
# port.c \(6317bytes\)
#
# file port.c checksum -r = 38660 13 port.c
echo Extracting port.c 1>&2
if test -f port.c ; then
echo will not overwrite port.c 1>&2
else
sed 's/^X//' > port.c <<\!!!EOF!!!
X#ident " @(#) port.c: Author - R. L. Bolin 1.9 90/02/21 "
X/*
X Program to control 386 UNIX EGA/VGA attribute registers for color
X background, forground and screen blanking
X Common use "port b", gives blue background and whit letters.
X "port s #", sets one attribute"
X "port x", blanks screen until another port command is given.
X
X Note: This is not a finished program, it still needs some work and could
X use some enhancements, like saving the virtual attributes so that
X each virtual screen could have its own color. This version sets all
X virtual consoles to the same color. On occasion my VGA card (SIGMA)
X VGA does not always respond correctly after several selections have
X been tested. Must be somthing in the INB to the register. Hope someone
X has the time and want to take this further and pass along. It works
X and has been tested on ISC and ESIX V3.2.
X
X Feel free to copy and enhance this code. Just post any
X updates on this news group.
X Ron Bolin
X BellSouth Services Atlanta, GA 404-529-3945
X*/
X
X#include <stdio.h>
X#include <sys/types.h>
X
X#define KIOC ('K'<<8)
X#define KDSBORDER (KIOC|13) /* set ega color border */
X#define KDENABIO (KIOC|60) /* enable direct I/O to ports */
X#define KDDISABIO (KIOC|61) /* disable direct I/O to ports */
X
X/*
X* INLINE i386 ASM CODE FOR OUTB TO CPU MEMORY
X*/
X#ifndef INLINE
Xasm int outb(port,val)
X{
X%reg port,val;
X movl port, %edx
X movl val, %eax
X outb (%dx)
X%reg port; mem val;
X movl port, %edx
X movb val, %al
X outb (%dx)
X%mem port; reg val;
X movw port, %dx
X movl val, %eax
X outb (%dx)
X%mem port,val;
X movw port, %dx
X movb val, %al
X outb (%dx)
X}
X
X/*
X* INLINE i386 ASM CODE FOR INB FROM CPU MEMORY
X*/
X
Xasm int inb(port)
X{
X%reg port;
X subl %eax, %eax
X movl port, %edx
X inb (%dx)
X%mem port;
X subl %eax, %eax
X movw port, %dx
X inb (%dx)
X}
X
X#else
X#include "inline.h"
X#endif
X
X/*
X*
X* main() - EGA/VGA port control, 1-2 calls in 1 cmd line
X*
X*/
X
X/* Not used now */
X/* NOTUSED */
X#define black 30
X#define red 31
X#define green 32
X#define yellow 33
X#define blue 34
X#define magenta 35
X#define cyan 36
X#define white 37
X
Xint memfd; /* ptr to device */
Xchar name[30]; /* device name storage */
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X
X ushort port, port1, data1, data2;
X extern int inb(), outb(), errno;
X extern void color();
X char *tty(), *DEV = name;
X struct kd_memloc *kdmem;
X struct reginfo *rgi;
X
X if(argc == 1) {
X fprintf(stderr,"%s: Usage: port <F color #> <B color #> \n",argv[0]);
X fprintf(stderr,"Usage:port <b> default background color blue\n");
X fprintf(stderr," [h] color help list\n");
X fprintf(stderr," [x] blank screen\n");
X fprintf(stderr," [s] color # (set color)\n");
X exit(1);
X }
X if(argc == 2 && (strcmp(argv[1],"h") == 0)) {
X fprintf(stderr,"Color Number Color\n");
X fprintf(stderr," 0 black\n");
X fprintf(stderr," 1 blue\n");
X fprintf(stderr," 2 green\n");
X fprintf(stderr," 3 cyan\n");
X fprintf(stderr," 4 red\n");
X fprintf(stderr," 5 magenta\n");
X fprintf(stderr," 6 brown\n");
X fprintf(stderr," 7 white\n");
X fprintf(stderr," 8 gray\n");
X fprintf(stderr," 9 lt blue\n");
X fprintf(stderr," A lt green\n");
X fprintf(stderr," B lt cyan\n");
X fprintf(stderr," C lt red\n");
X fprintf(stderr," D lt magenta\n");
X fprintf(stderr," E lt brown (yellow)\n");
X fprintf(stderr," F bright white\n");
X exit(0);
X }
X
X if(strcmp((DEV = tty()), "NOTTY") != 0) { /* get device name */
X if ((memfd = open(DEV, 2)) == -1) {
X perror(DEV);
X exit(1);
X }
X } else {
X perror("not a tty");
X exit(1);
X }
X if(argc == 3 && (strcmp(argv[1],"s") == 0)) {
X data1 = itox(argv[2]);
X if(data1 <= 0xf && data1 >= 0x0) {
X ioctl(memfd,KDENABIO,0);/* Enable i/o to port */
X inb(0x3da); /* clear input stat reg */
X outb(0x3c0,0x20); /* Select pallet Enable */
X errno=0;
X outb(0x3c0,data1); /* Select color */
X if(errno)
X fprintf(stderr,"Error outb %d\n",errno);
X ioctl(memfd,KDDISABIO,0);/* Disable i/o to port */
X }
X else
X fprintf(stderr,"%s:input range not 0x0 - 0xf\n",argv[0]);
X close(memfd);
X exit(1);
X }
X if(argc == 2 && (strcmp(argv[1],"x") == 0)) {
X ioctl(memfd,KDENABIO,0); /* Enable i/o to port */
X inb(0x3da); /* clear input stat reg */
X errno=0;
X outb(0x3c0,0x0); /* turn screen off */
X if(errno)
X fprintf(stderr,"Error outb %d\n",errno);
X ioctl(memfd,KDDISABIO,0); /* Disable i/o to port */
X close(memfd);
X exit(1);
X }
X if(argc == 2 && (strcmp(argv[1],"b") == 0)) {
X ioctl(memfd,KDENABIO,0); /* Enable i/o to port */
X inb(0x3da); /* clear input stat reg */
X errno=0;
X outb(0x3c0,0x20); /* Select pallet Enable */
X outb(0x3c0,0x7); /* Select forgnd white */
X inb(0x3da); /* clear input stat reg */
X outb(0x3c0,0x20); /* Select pallet Enable */
X outb(0x3c0,0x1); /* Select backgnd blue */
X if(errno)
X fprintf(stderr,"Error outb %d\n",errno);
X ioctl(memfd,KDDISABIO,0); /* Disable i/o to port */
X close(memfd);
X exit(1);
X }
X if(argv[1] != 0 && argv[2] != 0) { /* check args */
X data1 = itox(argv[1]);
X data2 = itox(argv[2]);
X if((data1 <= 0xf && data1 >= 0x0) && (data2 <= 0xf && data2 >= 0x0))
X {
X port = 0x3c0; /* attribute register port address */
X ioctl(memfd,KDENABIO,0); /* Enable i/o to port */
X inb(0x3da); /* clear input stat reg */
X errno=0;
X outb(0x3c0,0x20); /* Select pallet Enable */
X outb(port,data1); /* set foreground */
X inb(0x3da); /* clear input stat reg */
X outb(0x3c0,0x20); /* Select pallet Enable */
X outb(port,data2); /* set background */
X if(errno)
X fprintf(stderr,"%s: Error outb erron:%d\n",argv[0],errno);
X ioctl(memfd,KDDISABIO,0); /* Disable i/o to port */
X }
X else
X fprintf(stderr,"%s: 2 args or input range not 0x0 - 0xf\n",argv[0]);
X }
X
X
X if(memfd) close(memfd); /* close device prt */
X}
X
Xitox(s)
Xchar *s;
X{
X int x;
X
X sscanf(s, "%x", &x); /* convert to hex */
X return x;
X}
X
X/*
X*
X* tty() - make sure we are calling from a tty
X*
X*
X*/
X
X#include "sys/stermio.h"
X
Xchar *ttyname();
X
Xextern int optind;
Xint lflg;
Xint sflg;
X
Xchar *tty()
X{
X char *p;
X register int i;
X p = name;
X
X p = ttyname(0);
X return( (p? p: "NOTTY"));
X}
X
X/* NOTUSED */
Xvoid color(color)
Xint color;
X{
Xfprintf(stdout,"\033\1330m\033\133%dm",color);
X}
!!!EOF!!!
if [ "`sum -r port.c`" -ne "38660 13 port.c" ]
then
echo WARNING port.c: extractions error
fi
fi
--
Ron Bolin (404) 529-3945
BellSouth Services Switching Technical Support
Rm 25M64 675 W. Peachtree St. Atlanta, Ga 30375
..!gatech!sbmsg1!bsts00!rlb
More information about the Comp.unix.sysv386
mailing list