NetBSD/sys/arch/vax/vsa/smg.c

421 lines
9.6 KiB
C
Raw Normal View History

/* $NetBSD: smg.c,v 1.4 1998/06/20 21:59:44 drochner Exp $ */
/*
* Copyright (c) 1998 Ludd, University of Lule}, Sweden.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed at Ludd, University of
* Lule}, Sweden and its contributors.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/malloc.h>
#include <sys/conf.h>
#include <dev/cons.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wscons_callbacks.h>
#include <machine/vsbus.h>
#include <machine/sid.h>
#include "lkc.h"
#define SM_COLS 128 /* char width of screen */
#define SM_ROWS 57 /* rows of char on screen */
#define SM_CHEIGHT 15 /* lines a char consists of */
#define SM_NEXTROW (SM_COLS * SM_CHEIGHT)
static int smg_match __P((struct device *, struct cfdata *, void *));
static void smg_attach __P((struct device *, struct device *, void *));
struct smg_softc {
struct device ss_dev;
};
struct cfattach smg_ca = {
sizeof(struct smg_softc), smg_match, smg_attach,
};
static void smg_cursor __P((void *, int, int, int));
static void smg_putchar __P((void *, int, int, u_int, long));
static void smg_copycols __P((void *, int, int, int,int));
static void smg_erasecols __P((void *, int, int, int, long));
static void smg_copyrows __P((void *, int, int, int));
static void smg_eraserows __P((void *, int, int, long));
static int smg_alloc_attr __P((void *, int, int, int, long *));
const struct wsdisplay_emulops smg_emulops = {
smg_cursor,
smg_putchar,
smg_copycols,
smg_erasecols,
smg_copyrows,
smg_eraserows,
smg_alloc_attr
};
const struct wsscreen_descr smg_stdscreen = {
"128x57", 128, 57,
&smg_emulops,
8, 15,
0, /* WSSCREEN_UNDERLINE??? */
};
const struct wsscreen_descr *_smg_scrlist[] = {
&smg_stdscreen,
};
const struct wsscreen_list smg_screenlist = {
sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
_smg_scrlist,
};
static int smg_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
static int smg_mmap __P((void *, off_t, int));
static int smg_alloc_screen __P((void *, const struct wsscreen_descr *,
void **, int *, int *, long *));
static void smg_free_screen __P((void *, void *));
static void smg_show_screen __P((void *, void *));
static int smg_load_font __P((void *, void *, int, int, int, void *));
const struct wsdisplay_accessops smg_accessops = {
smg_ioctl,
smg_mmap,
smg_alloc_screen,
smg_free_screen,
smg_show_screen,
smg_load_font
};
struct smg_screen {
int ss_curx;
int ss_cury;
1998-06-06 02:02:56 +04:00
u_char ss_image[SM_ROWS][SM_COLS]; /* Image of current screen */
};
1998-06-06 02:02:56 +04:00
static struct smg_screen smg_conscreen;
static struct smg_screen *curscr;
int
smg_match(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
struct vsbus_attach_args *va = aux;
if (va->va_type != INR_VF)
return 0;
#ifdef DIAGNOSTIC
if (sm_addr == 0)
panic("smg: inconsistency in smg address mapping");
#endif
return 1;
}
void
smg_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct wsemuldisplaydev_attach_args aa;
printf("\n");
1998-06-06 02:02:56 +04:00
curscr = &smg_conscreen;
aa.console = !(vax_confdata & 0x20);
aa.scrdata = &smg_screenlist;
aa.accessops = &smg_accessops;
config_found(self, &aa, wsemuldisplaydevprint);
}
void
smg_cursor(id, on, row, col)
void *id;
int on, row, col;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = id;
ss->ss_curx = col;
ss->ss_cury = row;
if (ss == curscr)
sm_addr[(row * 15 * 128) + col + (14 * 128)] = on ? 255 : 0;
}
static void
smg_putchar(id, row, col, c, attr)
void *id;
int row, col;
u_int c;
long attr;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = id;
int i;
extern char q_font[];
c &= 0xff;
ss->ss_image[row][col] = c;
1998-06-06 02:02:56 +04:00
if (ss != curscr)
return;
for (i = 0; i < 15; i++)
sm_addr[col + (row * 15 * 128) + i * 128] =
q_font[(c - 32) * 15 + i];
}
/*
* copies columns inside a row.
*/
static void
smg_copycols(id, row, srccol, dstcol, ncols)
void *id;
int row, srccol, dstcol, ncols;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = id;
int i;
1998-06-06 02:02:56 +04:00
bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
if (ss != curscr)
return;
for (i = 0; i < SM_CHEIGHT; i++)
bcopy(&sm_addr[(row * SM_NEXTROW) + srccol + (i * 128)],
&sm_addr[(row * SM_NEXTROW) + dstcol + i*128], ncols);
}
/*
* Erases a bunch of chars inside one row.
*/
static void
smg_erasecols(id, row, startcol, ncols, fillattr)
void *id;
int row, startcol, ncols;
long fillattr;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = id;
int i;
1998-06-06 02:02:56 +04:00
bzero(&ss->ss_image[row][startcol], ncols);
if (ss != curscr)
return;
for (i = 0; i < SM_CHEIGHT; i++)
bzero(&sm_addr[(row * SM_NEXTROW) + startcol + i * 128], ncols);
}
static void
smg_copyrows(id, srcrow, dstrow, nrows)
void *id;
int srcrow, dstrow, nrows;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = id;
int frows;
1998-06-06 02:02:56 +04:00
bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0], nrows * 128);
if (ss != curscr)
return;
if (nrows > 25) {
frows = nrows >> 1;
if (srcrow > dstrow) {
bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
&sm_addr[(dstrow * SM_NEXTROW)],
frows * SM_NEXTROW);
bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
&sm_addr[((dstrow + frows) * SM_NEXTROW)],
(nrows - frows) * SM_NEXTROW);
} else {
bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
&sm_addr[((dstrow + frows) * SM_NEXTROW)],
(nrows - frows) * SM_NEXTROW);
bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
&sm_addr[(dstrow * SM_NEXTROW)],
frows * SM_NEXTROW);
}
} else
bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
&sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
}
static void
smg_eraserows(id, startrow, nrows, fillattr)
void *id;
int startrow, nrows;
long fillattr;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = id;
int frows;
1998-06-06 02:02:56 +04:00
bzero(&ss->ss_image[startrow][0], nrows * 128);
if (ss != curscr)
return;
if (nrows > 25) {
frows = nrows >> 1;
bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
(nrows - frows) * SM_NEXTROW);
} else
bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
}
static int
smg_alloc_attr(id, fg, bg, flags, attrp)
void *id;
int fg, bg;
int flags;
long *attrp;
{
return 0;
}
int
smg_ioctl(v, cmd, data, flag, p)
void *v;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
return -1;
}
static int
smg_mmap(v, offset, prot)
void *v;
off_t offset;
int prot;
{
return -1;
}
int
smg_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
void *v;
const struct wsscreen_descr *type;
void **cookiep;
int *curxp, *curyp;
long *defattrp;
{
1998-06-06 02:02:56 +04:00
*cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
bzero(*cookiep, sizeof(struct smg_screen));
*curxp = *curyp = *defattrp = 0;
return 0;
}
void
smg_free_screen(v, cookie)
void *v;
void *cookie;
{
}
void
smg_show_screen(v, cookie)
void *v;
void *cookie;
{
1998-06-06 02:02:56 +04:00
struct smg_screen *ss = cookie;
int row, col, line;
extern char q_font[];
if (ss == curscr)
return;
for (row = 0; row < 57; row++)
for (line = 0; line < 15; line++)
for (col = 0; col < 128; col++) {
u_char c = ss->ss_image[row][col];
if (c > 0x9f)
c -= 64;
else if (c > 0x1f)
c -= 32;
sm_addr[row * 128 * 15 + line * 128 + col] =
q_font[c * 15 + line];
}
curscr = ss;
}
static int
smg_load_font(v, cookie, first, num, stride, data)
void *v;
void *cookie;
int first, num, stride;
void *data;
{
return 0;
}
cons_decl(smg);
#define WSCONSOLEMAJOR 68
void
smgcninit(cndev)
struct consdev *cndev;
{
extern void lkccninit __P((struct consdev *));
extern int lkccngetc __P((dev_t));
/* Clear screen */
blkclr(sm_addr, 128*864);
1998-06-06 02:02:56 +04:00
curscr = &smg_conscreen;
wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
cn_tab->cn_dev = makedev(WSCONSOLEMAJOR, 0);
#if NLKC
lkccninit(cndev);
wsdisplay_set_cons_kbd(lkccngetc, nullcnpollc);
#endif
}
int smgprobe(void);
int
smgprobe()
{
switch (vax_boardtype) {
case VAX_BTYP_410:
case VAX_BTYP_420:
case VAX_BTYP_43:
if (vax_confdata & 0x20) /* doesn't use graphics console */
break;
if (sm_addr == 0) /* Haven't mapped graphic area */
break;
return 1;
default:
break;
}
return 0;
}