Home | History | Annotate | Line # | Download | only in ic
pcdisplay_subr.c revision 1.9.8.1
      1  1.9.8.1  wrstuden /* $NetBSD: pcdisplay_subr.c,v 1.9.8.1 1999/12/27 18:34:50 wrstuden Exp $ */
      2      1.1  drochner 
      3      1.1  drochner /*
      4      1.1  drochner  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5      1.1  drochner  * All rights reserved.
      6      1.1  drochner  *
      7      1.1  drochner  * Author: Chris G. Demetriou
      8      1.1  drochner  *
      9      1.1  drochner  * Permission to use, copy, modify and distribute this software and
     10      1.1  drochner  * its documentation is hereby granted, provided that both the copyright
     11      1.1  drochner  * notice and this permission notice appear in all copies of the
     12      1.1  drochner  * software, derivative works or modified versions, and any portions
     13      1.1  drochner  * thereof, and that both notices appear in supporting documentation.
     14      1.1  drochner  *
     15      1.1  drochner  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16      1.1  drochner  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17      1.1  drochner  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18      1.1  drochner  *
     19      1.1  drochner  * Carnegie Mellon requests users of this software to return to
     20      1.1  drochner  *
     21      1.1  drochner  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22      1.1  drochner  *  School of Computer Science
     23      1.1  drochner  *  Carnegie Mellon University
     24      1.1  drochner  *  Pittsburgh PA 15213-3890
     25      1.1  drochner  *
     26      1.1  drochner  * any improvements or extensions that they make and grant Carnegie the
     27      1.1  drochner  * rights to redistribute these changes.
     28      1.1  drochner  */
     29      1.1  drochner 
     30      1.1  drochner #include <sys/param.h>
     31      1.1  drochner #include <sys/systm.h>
     32      1.1  drochner #include <sys/device.h>
     33      1.1  drochner #include <machine/bus.h>
     34      1.1  drochner 
     35      1.1  drochner #include <dev/isa/isavar.h>
     36      1.1  drochner #include <dev/isa/isareg.h>
     37      1.1  drochner 
     38      1.1  drochner #include <dev/ic/mc6845reg.h>
     39      1.1  drochner #include <dev/ic/pcdisplayvar.h>
     40      1.1  drochner 
     41      1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     42      1.1  drochner 
     43  1.9.8.1  wrstuden #include "vga.h"
     44  1.9.8.1  wrstuden 
     45      1.1  drochner void
     46      1.1  drochner pcdisplay_cursor(id, on, row, col)
     47      1.1  drochner 	void *id;
     48      1.1  drochner 	int on, row, col;
     49      1.1  drochner {
     50      1.7        ad #ifdef PCDISPLAY_SOFTCURSOR
     51      1.7        ad 	struct pcdisplayscreen *scr = id;
     52      1.7        ad 	bus_space_tag_t memt = scr->hdl->ph_memt;
     53      1.7        ad 	bus_space_handle_t memh = scr->hdl->ph_memh;
     54      1.7        ad 	int off;
     55  1.9.8.1  wrstuden #if NVGA == 0
     56  1.9.8.1  wrstuden 	static int hwoff;
     57  1.9.8.1  wrstuden 
     58  1.9.8.1  wrstuden 	/*
     59  1.9.8.1  wrstuden 	 * If the VGA driver hasn't been included in the kernel, we
     60  1.9.8.1  wrstuden 	 * need to turn the hardware cursor off here.
     61  1.9.8.1  wrstuden 	 */
     62  1.9.8.1  wrstuden 	if (hwoff == 0) {
     63  1.9.8.1  wrstuden 		pcdisplay_6845_write(scr->hdl, cursorh, 0x10);
     64  1.9.8.1  wrstuden 		pcdisplay_6845_write(scr->hdl, cursorl, 0x10);
     65  1.9.8.1  wrstuden 		hwoff = 1;
     66  1.9.8.1  wrstuden 	}
     67  1.9.8.1  wrstuden #endif	/* NVGA == 0 */
     68      1.7        ad 
     69      1.7        ad 	/* Remove old cursor image */
     70      1.7        ad 	if (scr->cursoron) {
     71      1.7        ad 		off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
     72      1.7        ad 		if (scr->active)
     73      1.7        ad 			bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
     74      1.7        ad 			    scr->cursortmp);
     75      1.7        ad 		else
     76      1.7        ad 			scr->mem[off] = scr->cursortmp;
     77      1.7        ad 	}
     78      1.7        ad 
     79      1.7        ad 	scr->vc_crow = row;
     80      1.7        ad 	scr->vc_ccol = col;
     81      1.7        ad 
     82      1.7        ad 	if ((scr->cursoron = on) == 0)
     83      1.7        ad 		return;
     84      1.7        ad 
     85      1.7        ad 	off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
     86      1.8        ad 	if (scr->active) {
     87      1.8        ad 		off <<= 1;
     88      1.8        ad 		scr->cursortmp = bus_space_read_2(memt, memh,
     89      1.8        ad 		    scr->dispoffset + off);
     90      1.8        ad 		bus_space_write_2(memt, memh, scr->dispoffset + off,
     91      1.9        ad 		    scr->cursortmp ^ 0x7700);
     92      1.8        ad 	} else {
     93      1.8        ad 		scr->cursortmp = scr->mem[off];
     94      1.9        ad 		scr->mem[off] = scr->cursortmp ^ 0x7700;
     95      1.8        ad 	}
     96      1.7        ad #else 	/* PCDISPLAY_SOFTCURSOR */
     97      1.1  drochner 	struct pcdisplayscreen *scr = id;
     98      1.1  drochner 	int pos;
     99      1.1  drochner 
    100      1.1  drochner 	scr->vc_crow = row;
    101      1.1  drochner 	scr->vc_ccol = col;
    102      1.1  drochner 	scr->cursoron = on;
    103      1.1  drochner 
    104      1.1  drochner 	if (scr->active) {
    105      1.7        ad 		if (!on)
    106      1.7        ad 			pos = 0x1010;
    107      1.7        ad 		else
    108      1.6  drochner 			pos = scr->dispoffset / 2
    109      1.6  drochner 				+ row * scr->type->ncols + col;
    110      1.1  drochner 
    111      1.1  drochner 		pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
    112      1.1  drochner 		pcdisplay_6845_write(scr->hdl, cursorl, pos);
    113      1.1  drochner 	}
    114      1.7        ad #endif	/* PCDISPLAY_SOFTCURSOR */
    115      1.1  drochner }
    116      1.1  drochner 
    117      1.5  drochner #if 0
    118      1.5  drochner unsigned int
    119      1.5  drochner pcdisplay_mapchar_simple(id, uni)
    120      1.5  drochner 	void *id;
    121      1.5  drochner 	int uni;
    122      1.4  drochner {
    123      1.5  drochner 	if (uni < 128)
    124      1.5  drochner 		return (uni);
    125      1.5  drochner 
    126      1.5  drochner 	return (1); /* XXX ??? smiley */
    127      1.5  drochner }
    128      1.5  drochner #endif
    129      1.4  drochner 
    130      1.1  drochner void
    131      1.4  drochner pcdisplay_putchar(id, row, col, c, attr)
    132      1.1  drochner 	void *id;
    133      1.1  drochner 	int row, col;
    134      1.4  drochner 	u_int c;
    135      1.1  drochner 	long attr;
    136      1.1  drochner {
    137      1.1  drochner 	struct pcdisplayscreen *scr = id;
    138      1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    139      1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    140      1.4  drochner 	int off;
    141      1.1  drochner 
    142      1.1  drochner 	off = row * scr->type->ncols + col;
    143      1.1  drochner 
    144      1.4  drochner 	if (scr->active)
    145      1.6  drochner 		bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
    146      1.5  drochner 				  c | (attr << 8));
    147      1.4  drochner 	else
    148      1.5  drochner 		scr->mem[off] = c | (attr << 8);
    149      1.1  drochner }
    150      1.1  drochner 
    151      1.1  drochner void
    152      1.1  drochner pcdisplay_copycols(id, row, srccol, dstcol, ncols)
    153      1.1  drochner 	void *id;
    154      1.1  drochner 	int row, srccol, dstcol, ncols;
    155      1.1  drochner {
    156      1.1  drochner 	struct pcdisplayscreen *scr = id;
    157      1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    158      1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    159      1.1  drochner 	bus_size_t srcoff, dstoff;
    160      1.1  drochner 
    161      1.1  drochner 	srcoff = dstoff = row * scr->type->ncols;
    162      1.1  drochner 	srcoff += srccol;
    163      1.1  drochner 	dstoff += dstcol;
    164      1.1  drochner 
    165      1.1  drochner 	if (scr->active)
    166      1.6  drochner 		bus_space_copy_region_2(memt, memh,
    167      1.6  drochner 					scr->dispoffset + srcoff * 2,
    168      1.6  drochner 					memh, scr->dispoffset + dstoff * 2,
    169      1.6  drochner 					ncols);
    170      1.1  drochner 	else
    171      1.1  drochner 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
    172      1.1  drochner }
    173      1.1  drochner 
    174      1.1  drochner void
    175      1.1  drochner pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
    176      1.1  drochner 	void *id;
    177      1.1  drochner 	int row, startcol, ncols;
    178      1.1  drochner 	long fillattr;
    179      1.1  drochner {
    180      1.1  drochner 	struct pcdisplayscreen *scr = id;
    181      1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    182      1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    183      1.1  drochner 	bus_size_t off;
    184      1.1  drochner 	u_int16_t val;
    185      1.1  drochner 	int i;
    186      1.1  drochner 
    187      1.1  drochner 	off = row * scr->type->ncols + startcol;
    188      1.1  drochner 
    189      1.1  drochner 	val = (fillattr << 8) | ' ';
    190      1.1  drochner 
    191      1.1  drochner 	if (scr->active)
    192      1.6  drochner 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    193      1.6  drochner 				       val, ncols);
    194      1.1  drochner 	else
    195      1.1  drochner 		for (i = 0; i < ncols; i++)
    196      1.1  drochner 			scr->mem[off + i] = val;
    197      1.1  drochner }
    198      1.1  drochner 
    199      1.1  drochner void
    200      1.1  drochner pcdisplay_copyrows(id, srcrow, dstrow, nrows)
    201      1.1  drochner 	void *id;
    202      1.1  drochner 	int srcrow, dstrow, nrows;
    203      1.1  drochner {
    204      1.1  drochner 	struct pcdisplayscreen *scr = id;
    205      1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    206      1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    207      1.1  drochner 	int ncols = scr->type->ncols;
    208      1.1  drochner 	bus_size_t srcoff, dstoff;
    209      1.1  drochner 
    210      1.1  drochner 	srcoff = srcrow * ncols + 0;
    211      1.1  drochner 	dstoff = dstrow * ncols + 0;
    212      1.1  drochner 
    213      1.1  drochner 	if (scr->active)
    214      1.6  drochner 		bus_space_copy_region_2(memt, memh,
    215      1.6  drochner 					scr->dispoffset + srcoff * 2,
    216      1.6  drochner 					memh, scr->dispoffset + dstoff * 2,
    217      1.6  drochner 					nrows * ncols);
    218      1.1  drochner 	else
    219      1.1  drochner 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
    220      1.1  drochner 		      nrows * ncols * 2);
    221      1.1  drochner }
    222      1.1  drochner 
    223      1.1  drochner void
    224      1.1  drochner pcdisplay_eraserows(id, startrow, nrows, fillattr)
    225      1.1  drochner 	void *id;
    226      1.1  drochner 	int startrow, nrows;
    227      1.1  drochner 	long fillattr;
    228      1.1  drochner {
    229      1.1  drochner 	struct pcdisplayscreen *scr = id;
    230      1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    231      1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    232      1.1  drochner 	bus_size_t off, count;
    233      1.1  drochner 	u_int16_t val;
    234      1.1  drochner 	int i;
    235      1.1  drochner 
    236      1.1  drochner 	off = startrow * scr->type->ncols;
    237      1.1  drochner 	count = nrows * scr->type->ncols;
    238      1.1  drochner 
    239      1.1  drochner 	val = (fillattr << 8) | ' ';
    240      1.1  drochner 
    241      1.1  drochner 	if (scr->active)
    242      1.6  drochner 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    243      1.6  drochner 				       val, count);
    244      1.1  drochner 	else
    245      1.1  drochner 		for (i = 0; i < count; i++)
    246      1.1  drochner 			scr->mem[off + i] = val;
    247      1.1  drochner }
    248