Home | History | Annotate | Line # | Download | only in ic
pcdisplay_subr.c revision 1.8
      1 /* $NetBSD: pcdisplay_subr.c,v 1.8 1999/09/19 23:00:04 ad 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 void
     44 pcdisplay_cursor(id, on, row, col)
     45 	void *id;
     46 	int on, row, col;
     47 {
     48 #ifdef PCDISPLAY_SOFTCURSOR
     49 	struct pcdisplayscreen *scr = id;
     50 	bus_space_tag_t memt = scr->hdl->ph_memt;
     51 	bus_space_handle_t memh = scr->hdl->ph_memh;
     52 	int off;
     53 
     54 	/* Remove old cursor image */
     55 	if (scr->cursoron) {
     56 		off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
     57 		if (scr->active)
     58 			bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
     59 			    scr->cursortmp);
     60 		else
     61 			scr->mem[off] = scr->cursortmp;
     62 	}
     63 
     64 	scr->vc_crow = row;
     65 	scr->vc_ccol = col;
     66 
     67 	if ((scr->cursoron = on) == 0)
     68 		return;
     69 
     70 	off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
     71 	if (scr->active) {
     72 		off <<= 1;
     73 		scr->cursortmp = bus_space_read_2(memt, memh,
     74 		    scr->dispoffset + off);
     75 		bus_space_write_2(memt, memh, scr->dispoffset + off,
     76 		    scr->cursortmp ^ 0x7000);
     77 	} else {
     78 		scr->cursortmp = scr->mem[off];
     79 		scr->mem[off] = scr->cursortmp ^ 0x7000;
     80 	}
     81 #else 	/* PCDISPLAY_SOFTCURSOR */
     82 	struct pcdisplayscreen *scr = id;
     83 	int pos;
     84 
     85 	scr->vc_crow = row;
     86 	scr->vc_ccol = col;
     87 	scr->cursoron = on;
     88 
     89 	if (scr->active) {
     90 		if (!on)
     91 			pos = 0x1010;
     92 		else
     93 			pos = scr->dispoffset / 2
     94 				+ row * scr->type->ncols + col;
     95 
     96 		pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
     97 		pcdisplay_6845_write(scr->hdl, cursorl, pos);
     98 	}
     99 #endif	/* PCDISPLAY_SOFTCURSOR */
    100 }
    101 
    102 #if 0
    103 unsigned int
    104 pcdisplay_mapchar_simple(id, uni)
    105 	void *id;
    106 	int uni;
    107 {
    108 	if (uni < 128)
    109 		return (uni);
    110 
    111 	return (1); /* XXX ??? smiley */
    112 }
    113 #endif
    114 
    115 void
    116 pcdisplay_putchar(id, row, col, c, attr)
    117 	void *id;
    118 	int row, col;
    119 	u_int c;
    120 	long attr;
    121 {
    122 	struct pcdisplayscreen *scr = id;
    123 	bus_space_tag_t memt = scr->hdl->ph_memt;
    124 	bus_space_handle_t memh = scr->hdl->ph_memh;
    125 	int off;
    126 
    127 
    128 	off = row * scr->type->ncols + col;
    129 
    130 	if (scr->active)
    131 		bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
    132 				  c | (attr << 8));
    133 	else
    134 		scr->mem[off] = c | (attr << 8);
    135 }
    136 
    137 void
    138 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
    139 	void *id;
    140 	int row, srccol, dstcol, ncols;
    141 {
    142 	struct pcdisplayscreen *scr = id;
    143 	bus_space_tag_t memt = scr->hdl->ph_memt;
    144 	bus_space_handle_t memh = scr->hdl->ph_memh;
    145 	bus_size_t srcoff, dstoff;
    146 
    147 	srcoff = dstoff = row * scr->type->ncols;
    148 	srcoff += srccol;
    149 	dstoff += dstcol;
    150 
    151 	if (scr->active)
    152 		bus_space_copy_region_2(memt, memh,
    153 					scr->dispoffset + srcoff * 2,
    154 					memh, scr->dispoffset + dstoff * 2,
    155 					ncols);
    156 	else
    157 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
    158 }
    159 
    160 void
    161 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
    162 	void *id;
    163 	int row, startcol, ncols;
    164 	long fillattr;
    165 {
    166 	struct pcdisplayscreen *scr = id;
    167 	bus_space_tag_t memt = scr->hdl->ph_memt;
    168 	bus_space_handle_t memh = scr->hdl->ph_memh;
    169 	bus_size_t off;
    170 	u_int16_t val;
    171 	int i;
    172 
    173 	off = row * scr->type->ncols + startcol;
    174 
    175 	val = (fillattr << 8) | ' ';
    176 
    177 	if (scr->active)
    178 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    179 				       val, ncols);
    180 	else
    181 		for (i = 0; i < ncols; i++)
    182 			scr->mem[off + i] = val;
    183 }
    184 
    185 void
    186 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
    187 	void *id;
    188 	int srcrow, dstrow, nrows;
    189 {
    190 	struct pcdisplayscreen *scr = id;
    191 	bus_space_tag_t memt = scr->hdl->ph_memt;
    192 	bus_space_handle_t memh = scr->hdl->ph_memh;
    193 	int ncols = scr->type->ncols;
    194 	bus_size_t srcoff, dstoff;
    195 
    196 	srcoff = srcrow * ncols + 0;
    197 	dstoff = dstrow * ncols + 0;
    198 
    199 	if (scr->active)
    200 		bus_space_copy_region_2(memt, memh,
    201 					scr->dispoffset + srcoff * 2,
    202 					memh, scr->dispoffset + dstoff * 2,
    203 					nrows * ncols);
    204 	else
    205 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
    206 		      nrows * ncols * 2);
    207 }
    208 
    209 void
    210 pcdisplay_eraserows(id, startrow, nrows, fillattr)
    211 	void *id;
    212 	int startrow, nrows;
    213 	long fillattr;
    214 {
    215 	struct pcdisplayscreen *scr = id;
    216 	bus_space_tag_t memt = scr->hdl->ph_memt;
    217 	bus_space_handle_t memh = scr->hdl->ph_memh;
    218 	bus_size_t off, count;
    219 	u_int16_t val;
    220 	int i;
    221 
    222 	off = startrow * scr->type->ncols;
    223 	count = nrows * scr->type->ncols;
    224 
    225 	val = (fillattr << 8) | ' ';
    226 
    227 	if (scr->active)
    228 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    229 				       val, count);
    230 	else
    231 		for (i = 0; i < count; i++)
    232 			scr->mem[off + i] = val;
    233 }
    234