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