Home | History | Annotate | Line # | Download | only in ic
pcdisplay_subr.c revision 1.1
      1 /* $NetBSD: pcdisplay_subr.c,v 1.1 1998/05/28 16:48:40 drochner 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 	struct pcdisplayscreen *scr = id;
     49 	int pos;
     50 
     51 #if 0
     52 	printf("pcdisplay_cursor: %d %d\n", row, col);
     53 #endif
     54 	scr->vc_crow = row;
     55 	scr->vc_ccol = col;
     56 	scr->cursoron = on;
     57 
     58 	if (scr->active) {
     59 		if (!on) {
     60 			/* XXX disable cursor how??? */
     61 			row = col = -1;
     62 		}
     63 
     64 		pos = row * scr->type->ncols + col;
     65 
     66 		pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
     67 		pcdisplay_6845_write(scr->hdl, cursorl, pos);
     68 	}
     69 }
     70 
     71 void
     72 pcdisplay_putstr(id, row, col, cp, len, attr)
     73 	void *id;
     74 	int row, col;
     75 	char *cp;
     76 	int len;
     77 	long attr;
     78 {
     79 	struct pcdisplayscreen *scr = id;
     80 	bus_space_tag_t memt = scr->hdl->ph_memt;
     81 	bus_space_handle_t memh = scr->hdl->ph_memh;
     82 	int i, off;
     83 
     84 	off = row * scr->type->ncols + col;
     85 
     86 	if (scr->active) {
     87 		off *= 2;
     88 
     89 		for (i = 0; i < len; i++, cp++, off += 2)
     90 			bus_space_write_2(memt, memh, off, (attr << 8) | *cp);
     91 	} else {
     92 		u_int16_t *m = &scr->mem[off];
     93 
     94 		for (i = 0; i < len; i++, cp++)
     95 			*m++ = *cp | (attr << 8);
     96 	}
     97 }
     98 
     99 void
    100 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
    101 	void *id;
    102 	int row, srccol, dstcol, ncols;
    103 {
    104 	struct pcdisplayscreen *scr = id;
    105 	bus_space_tag_t memt = scr->hdl->ph_memt;
    106 	bus_space_handle_t memh = scr->hdl->ph_memh;
    107 	bus_size_t srcoff, dstoff;
    108 
    109 	srcoff = dstoff = row * scr->type->ncols;
    110 	srcoff += srccol;
    111 	dstoff += dstcol;
    112 
    113 	if (scr->active)
    114 		bus_space_copy_region_2(memt, memh, srcoff * 2,
    115 					memh, dstoff * 2, ncols);
    116 	else
    117 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
    118 }
    119 
    120 void
    121 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
    122 	void *id;
    123 	int row, startcol, ncols;
    124 	long fillattr;
    125 {
    126 	struct pcdisplayscreen *scr = id;
    127 	bus_space_tag_t memt = scr->hdl->ph_memt;
    128 	bus_space_handle_t memh = scr->hdl->ph_memh;
    129 	bus_size_t off;
    130 	u_int16_t val;
    131 	int i;
    132 
    133 	off = row * scr->type->ncols + startcol;
    134 
    135 	val = (fillattr << 8) | ' ';
    136 
    137 	if (scr->active)
    138 		bus_space_set_region_2(memt, memh, off * 2, val, ncols);
    139 	else
    140 		for (i = 0; i < ncols; i++)
    141 			scr->mem[off + i] = val;
    142 }
    143 
    144 void
    145 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
    146 	void *id;
    147 	int srcrow, dstrow, nrows;
    148 {
    149 	struct pcdisplayscreen *scr = id;
    150 	bus_space_tag_t memt = scr->hdl->ph_memt;
    151 	bus_space_handle_t memh = scr->hdl->ph_memh;
    152 	int ncols = scr->type->ncols;
    153 	bus_size_t srcoff, dstoff;
    154 
    155 	srcoff = srcrow * ncols + 0;
    156 	dstoff = dstrow * ncols + 0;
    157 
    158 	if (scr->active)
    159 		bus_space_copy_region_2(memt, memh, srcoff * 2,
    160 					memh, dstoff * 2, nrows * ncols);
    161 	else
    162 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
    163 		      nrows * ncols * 2);
    164 }
    165 
    166 void
    167 pcdisplay_eraserows(id, startrow, nrows, fillattr)
    168 	void *id;
    169 	int startrow, nrows;
    170 	long fillattr;
    171 {
    172 	struct pcdisplayscreen *scr = id;
    173 	bus_space_tag_t memt = scr->hdl->ph_memt;
    174 	bus_space_handle_t memh = scr->hdl->ph_memh;
    175 	bus_size_t off, count;
    176 	u_int16_t val;
    177 	int i;
    178 
    179 	off = startrow * scr->type->ncols;
    180 	count = nrows * scr->type->ncols;
    181 
    182 	val = (fillattr << 8) | ' ';
    183 
    184 	if (scr->active)
    185 		bus_space_set_region_2(memt, memh, off * 2, val, count);
    186 	else
    187 		for (i = 0; i < count; i++)
    188 			scr->mem[off + i] = val;
    189 }
    190