Home | History | Annotate | Line # | Download | only in ic
pcdisplay_subr.c revision 1.16
      1  1.16       cgd /* $NetBSD: pcdisplay_subr.c,v 1.16 2000/06/08 07:01:19 cgd 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/ic/mc6845reg.h>
     36   1.1  drochner #include <dev/ic/pcdisplayvar.h>
     37   1.1  drochner 
     38   1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     39  1.12        ad 
     40  1.12        ad void
     41  1.14        ad pcdisplay_cursor_init(scr, existing)
     42  1.12        ad 	struct pcdisplayscreen *scr;
     43  1.14        ad 	int existing;
     44  1.12        ad {
     45  1.14        ad #ifdef PCDISPLAY_SOFTCURSOR
     46  1.14        ad 	bus_space_tag_t memt;
     47  1.14        ad 	bus_space_handle_t memh;
     48  1.14        ad 	int off;
     49  1.12        ad 
     50  1.13        ad 	pcdisplay_6845_write(scr->hdl, curstart, 0x10);
     51  1.13        ad 	pcdisplay_6845_write(scr->hdl, curend, 0x10);
     52  1.14        ad 
     53  1.14        ad 	if (existing) {
     54  1.14        ad 		/*
     55  1.14        ad 		 * This is the first screen. At this point, scr->active is
     56  1.14        ad 		 * false and scr->mem is NULL (no backing store), so we
     57  1.14        ad 		 * can't use pcdisplay_cursor() to do this.
     58  1.14        ad 		 */
     59  1.14        ad 		memt = scr->hdl->ph_memt;
     60  1.14        ad 		memh = scr->hdl->ph_memh;
     61  1.14        ad 		off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol) * 2 +
     62  1.14        ad 		    scr->dispoffset;
     63  1.14        ad 
     64  1.14        ad 		scr->cursortmp = bus_space_read_2(memt, memh, off);
     65  1.14        ad 		bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
     66  1.15        ad 	} else
     67  1.15        ad 		scr->cursortmp = 0;
     68  1.12        ad #endif
     69  1.14        ad 	scr->cursoron = 1;
     70  1.12        ad }
     71   1.1  drochner 
     72   1.1  drochner void
     73   1.1  drochner pcdisplay_cursor(id, on, row, col)
     74   1.1  drochner 	void *id;
     75   1.1  drochner 	int on, row, col;
     76   1.1  drochner {
     77   1.7        ad #ifdef PCDISPLAY_SOFTCURSOR
     78   1.7        ad 	struct pcdisplayscreen *scr = id;
     79   1.7        ad 	bus_space_tag_t memt = scr->hdl->ph_memt;
     80   1.7        ad 	bus_space_handle_t memh = scr->hdl->ph_memh;
     81   1.7        ad 	int off;
     82   1.7        ad 
     83   1.7        ad 	/* Remove old cursor image */
     84   1.7        ad 	if (scr->cursoron) {
     85   1.7        ad 		off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
     86   1.7        ad 		if (scr->active)
     87   1.7        ad 			bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
     88   1.7        ad 			    scr->cursortmp);
     89   1.7        ad 		else
     90   1.7        ad 			scr->mem[off] = scr->cursortmp;
     91   1.7        ad 	}
     92   1.7        ad 
     93   1.7        ad 	scr->vc_crow = row;
     94   1.7        ad 	scr->vc_ccol = col;
     95   1.7        ad 
     96   1.7        ad 	if ((scr->cursoron = on) == 0)
     97   1.7        ad 		return;
     98   1.7        ad 
     99   1.7        ad 	off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
    100   1.8        ad 	if (scr->active) {
    101  1.14        ad 		off = off * 2 + scr->dispoffset;
    102  1.14        ad 		scr->cursortmp = bus_space_read_2(memt, memh, off);
    103  1.14        ad 		bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
    104   1.8        ad 	} else {
    105   1.8        ad 		scr->cursortmp = scr->mem[off];
    106   1.9        ad 		scr->mem[off] = scr->cursortmp ^ 0x7700;
    107   1.8        ad 	}
    108   1.7        ad #else 	/* PCDISPLAY_SOFTCURSOR */
    109   1.1  drochner 	struct pcdisplayscreen *scr = id;
    110   1.1  drochner 	int pos;
    111   1.1  drochner 
    112   1.1  drochner 	scr->vc_crow = row;
    113   1.1  drochner 	scr->vc_ccol = col;
    114   1.1  drochner 	scr->cursoron = on;
    115   1.1  drochner 
    116   1.1  drochner 	if (scr->active) {
    117   1.7        ad 		if (!on)
    118   1.7        ad 			pos = 0x1010;
    119   1.7        ad 		else
    120   1.6  drochner 			pos = scr->dispoffset / 2
    121   1.6  drochner 				+ row * scr->type->ncols + col;
    122   1.1  drochner 
    123   1.1  drochner 		pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
    124   1.1  drochner 		pcdisplay_6845_write(scr->hdl, cursorl, pos);
    125   1.1  drochner 	}
    126   1.7        ad #endif	/* PCDISPLAY_SOFTCURSOR */
    127   1.1  drochner }
    128   1.1  drochner 
    129   1.5  drochner #if 0
    130   1.5  drochner unsigned int
    131   1.5  drochner pcdisplay_mapchar_simple(id, uni)
    132   1.5  drochner 	void *id;
    133   1.5  drochner 	int uni;
    134   1.4  drochner {
    135   1.5  drochner 	if (uni < 128)
    136   1.5  drochner 		return (uni);
    137   1.5  drochner 
    138   1.5  drochner 	return (1); /* XXX ??? smiley */
    139   1.5  drochner }
    140   1.5  drochner #endif
    141   1.4  drochner 
    142   1.1  drochner void
    143   1.4  drochner pcdisplay_putchar(id, row, col, c, attr)
    144   1.1  drochner 	void *id;
    145   1.1  drochner 	int row, col;
    146   1.4  drochner 	u_int c;
    147   1.1  drochner 	long attr;
    148   1.1  drochner {
    149   1.1  drochner 	struct pcdisplayscreen *scr = id;
    150   1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    151   1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    152   1.4  drochner 	int off;
    153   1.1  drochner 
    154   1.1  drochner 	off = row * scr->type->ncols + col;
    155   1.1  drochner 
    156   1.4  drochner 	if (scr->active)
    157   1.6  drochner 		bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
    158   1.5  drochner 				  c | (attr << 8));
    159   1.4  drochner 	else
    160   1.5  drochner 		scr->mem[off] = c | (attr << 8);
    161   1.1  drochner }
    162   1.1  drochner 
    163   1.1  drochner void
    164   1.1  drochner pcdisplay_copycols(id, row, srccol, dstcol, ncols)
    165   1.1  drochner 	void *id;
    166   1.1  drochner 	int row, srccol, dstcol, ncols;
    167   1.1  drochner {
    168   1.1  drochner 	struct pcdisplayscreen *scr = id;
    169   1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    170   1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    171   1.1  drochner 	bus_size_t srcoff, dstoff;
    172   1.1  drochner 
    173   1.1  drochner 	srcoff = dstoff = row * scr->type->ncols;
    174   1.1  drochner 	srcoff += srccol;
    175   1.1  drochner 	dstoff += dstcol;
    176   1.1  drochner 
    177   1.1  drochner 	if (scr->active)
    178   1.6  drochner 		bus_space_copy_region_2(memt, memh,
    179   1.6  drochner 					scr->dispoffset + srcoff * 2,
    180   1.6  drochner 					memh, scr->dispoffset + dstoff * 2,
    181   1.6  drochner 					ncols);
    182   1.1  drochner 	else
    183   1.1  drochner 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
    184   1.1  drochner }
    185   1.1  drochner 
    186   1.1  drochner void
    187   1.1  drochner pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
    188   1.1  drochner 	void *id;
    189   1.1  drochner 	int row, startcol, ncols;
    190   1.1  drochner 	long fillattr;
    191   1.1  drochner {
    192   1.1  drochner 	struct pcdisplayscreen *scr = id;
    193   1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    194   1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    195   1.1  drochner 	bus_size_t off;
    196   1.1  drochner 	u_int16_t val;
    197   1.1  drochner 	int i;
    198   1.1  drochner 
    199   1.1  drochner 	off = row * scr->type->ncols + startcol;
    200   1.1  drochner 
    201   1.1  drochner 	val = (fillattr << 8) | ' ';
    202   1.1  drochner 
    203   1.1  drochner 	if (scr->active)
    204   1.6  drochner 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    205   1.6  drochner 				       val, ncols);
    206   1.1  drochner 	else
    207   1.1  drochner 		for (i = 0; i < ncols; i++)
    208   1.1  drochner 			scr->mem[off + i] = val;
    209   1.1  drochner }
    210   1.1  drochner 
    211   1.1  drochner void
    212   1.1  drochner pcdisplay_copyrows(id, srcrow, dstrow, nrows)
    213   1.1  drochner 	void *id;
    214   1.1  drochner 	int srcrow, dstrow, nrows;
    215   1.1  drochner {
    216   1.1  drochner 	struct pcdisplayscreen *scr = id;
    217   1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    218   1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    219   1.1  drochner 	int ncols = scr->type->ncols;
    220   1.1  drochner 	bus_size_t srcoff, dstoff;
    221   1.1  drochner 
    222   1.1  drochner 	srcoff = srcrow * ncols + 0;
    223   1.1  drochner 	dstoff = dstrow * ncols + 0;
    224   1.1  drochner 
    225   1.1  drochner 	if (scr->active)
    226   1.6  drochner 		bus_space_copy_region_2(memt, memh,
    227   1.6  drochner 					scr->dispoffset + srcoff * 2,
    228   1.6  drochner 					memh, scr->dispoffset + dstoff * 2,
    229   1.6  drochner 					nrows * ncols);
    230   1.1  drochner 	else
    231   1.1  drochner 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
    232   1.1  drochner 		      nrows * ncols * 2);
    233   1.1  drochner }
    234   1.1  drochner 
    235   1.1  drochner void
    236   1.1  drochner pcdisplay_eraserows(id, startrow, nrows, fillattr)
    237   1.1  drochner 	void *id;
    238   1.1  drochner 	int startrow, nrows;
    239   1.1  drochner 	long fillattr;
    240   1.1  drochner {
    241   1.1  drochner 	struct pcdisplayscreen *scr = id;
    242   1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    243   1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    244   1.1  drochner 	bus_size_t off, count;
    245   1.1  drochner 	u_int16_t val;
    246   1.1  drochner 	int i;
    247   1.1  drochner 
    248   1.1  drochner 	off = startrow * scr->type->ncols;
    249   1.1  drochner 	count = nrows * scr->type->ncols;
    250   1.1  drochner 
    251   1.1  drochner 	val = (fillattr << 8) | ' ';
    252   1.1  drochner 
    253   1.1  drochner 	if (scr->active)
    254   1.6  drochner 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    255   1.6  drochner 				       val, count);
    256   1.1  drochner 	else
    257   1.1  drochner 		for (i = 0; i < count; i++)
    258   1.1  drochner 			scr->mem[off + i] = val;
    259   1.1  drochner }
    260