Home | History | Annotate | Line # | Download | only in ic
pcdisplay_subr.c revision 1.25.8.1.4.1
      1  1.25.8.1.4.1    bouyer /* $NetBSD: pcdisplay_subr.c,v 1.25.8.1.4.1 2007/08/12 19:53:17 bouyer 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.20     lukem 
     30          1.20     lukem #include <sys/cdefs.h>
     31  1.25.8.1.4.1    bouyer __KERNEL_RCSID(0, "$NetBSD: pcdisplay_subr.c,v 1.25.8.1.4.1 2007/08/12 19:53:17 bouyer Exp $");
     32           1.1  drochner 
     33           1.1  drochner #include <sys/param.h>
     34           1.1  drochner #include <sys/systm.h>
     35           1.1  drochner #include <sys/device.h>
     36           1.1  drochner #include <machine/bus.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.21  christos #include <dev/wscons/wsconsio.h>
     41           1.1  drochner 
     42           1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     43          1.12        ad 
     44          1.22  christos #include "opt_wsdisplay_compat.h" /* for WSDISPLAY_CHARFUNCS */
     45          1.22  christos 
     46          1.12        ad void
     47          1.14        ad pcdisplay_cursor_init(scr, existing)
     48          1.12        ad 	struct pcdisplayscreen *scr;
     49          1.14        ad 	int existing;
     50          1.12        ad {
     51          1.14        ad #ifdef PCDISPLAY_SOFTCURSOR
     52          1.14        ad 	bus_space_tag_t memt;
     53          1.14        ad 	bus_space_handle_t memh;
     54          1.14        ad 	int off;
     55          1.12        ad 
     56          1.13        ad 	pcdisplay_6845_write(scr->hdl, curstart, 0x10);
     57          1.13        ad 	pcdisplay_6845_write(scr->hdl, curend, 0x10);
     58          1.14        ad 
     59          1.14        ad 	if (existing) {
     60          1.14        ad 		/*
     61          1.19  drochner 		 * This is the first screen. At this point, scr->mem is NULL
     62          1.19  drochner 		 * (no backing store), so we can't use pcdisplay_cursor() to
     63          1.19  drochner 		 * do this.
     64          1.14        ad 		 */
     65          1.14        ad 		memt = scr->hdl->ph_memt;
     66          1.14        ad 		memh = scr->hdl->ph_memh;
     67          1.23  junyoung 		off = (scr->cursorrow * scr->type->ncols + scr->cursorcol) * 2
     68          1.23  junyoung 		    + scr->dispoffset;
     69          1.14        ad 
     70          1.14        ad 		scr->cursortmp = bus_space_read_2(memt, memh, off);
     71          1.14        ad 		bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
     72          1.15        ad 	} else
     73          1.15        ad 		scr->cursortmp = 0;
     74          1.17   thorpej #else
     75          1.17   thorpej 	/*
     76          1.17   thorpej 	 * Firmware might not have initialized the cursor shape.  Make
     77          1.17   thorpej 	 * sure there's something we can see.
     78          1.19  drochner 	 * Don't touch the hardware if this is not the first screen.
     79          1.17   thorpej 	 */
     80          1.19  drochner 	if (existing) {
     81          1.19  drochner 		pcdisplay_6845_write(scr->hdl, curstart,
     82          1.19  drochner 				     scr->type->fontheight - 2);
     83          1.19  drochner 		pcdisplay_6845_write(scr->hdl, curend,
     84          1.19  drochner 				     scr->type->fontheight - 1);
     85          1.19  drochner 	}
     86          1.12        ad #endif
     87          1.14        ad 	scr->cursoron = 1;
     88          1.12        ad }
     89           1.1  drochner 
     90           1.1  drochner void
     91           1.1  drochner pcdisplay_cursor(id, on, row, col)
     92           1.1  drochner 	void *id;
     93           1.1  drochner 	int on, row, col;
     94           1.1  drochner {
     95           1.7        ad #ifdef PCDISPLAY_SOFTCURSOR
     96           1.7        ad 	struct pcdisplayscreen *scr = id;
     97           1.7        ad 	bus_space_tag_t memt = scr->hdl->ph_memt;
     98           1.7        ad 	bus_space_handle_t memh = scr->hdl->ph_memh;
     99           1.7        ad 	int off;
    100           1.7        ad 
    101           1.7        ad 	/* Remove old cursor image */
    102           1.7        ad 	if (scr->cursoron) {
    103          1.23  junyoung 		off = scr->cursorrow * scr->type->ncols + scr->cursorcol;
    104           1.7        ad 		if (scr->active)
    105           1.7        ad 			bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
    106           1.7        ad 			    scr->cursortmp);
    107           1.7        ad 		else
    108           1.7        ad 			scr->mem[off] = scr->cursortmp;
    109           1.7        ad 	}
    110           1.7        ad 
    111          1.23  junyoung 	scr->cursorrow = row;
    112          1.23  junyoung 	scr->cursorcol = col;
    113           1.7        ad 
    114           1.7        ad 	if ((scr->cursoron = on) == 0)
    115           1.7        ad 		return;
    116           1.7        ad 
    117          1.23  junyoung 	off = (scr->cursorrow * scr->type->ncols + scr->cursorcol);
    118           1.8        ad 	if (scr->active) {
    119          1.14        ad 		off = off * 2 + scr->dispoffset;
    120          1.14        ad 		scr->cursortmp = bus_space_read_2(memt, memh, off);
    121          1.14        ad 		bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
    122           1.8        ad 	} else {
    123           1.8        ad 		scr->cursortmp = scr->mem[off];
    124           1.9        ad 		scr->mem[off] = scr->cursortmp ^ 0x7700;
    125           1.8        ad 	}
    126           1.7        ad #else 	/* PCDISPLAY_SOFTCURSOR */
    127           1.1  drochner 	struct pcdisplayscreen *scr = id;
    128           1.1  drochner 	int pos;
    129           1.1  drochner 
    130          1.23  junyoung 	scr->cursorrow = row;
    131          1.24      tron 	scr->cursorcol = col;
    132           1.1  drochner 	scr->cursoron = on;
    133           1.1  drochner 
    134           1.1  drochner 	if (scr->active) {
    135           1.7        ad 		if (!on)
    136          1.19  drochner 			pos = 0x3fff;
    137           1.7        ad 		else
    138           1.6  drochner 			pos = scr->dispoffset / 2
    139           1.6  drochner 				+ row * scr->type->ncols + col;
    140           1.1  drochner 
    141           1.1  drochner 		pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
    142           1.1  drochner 		pcdisplay_6845_write(scr->hdl, cursorl, pos);
    143           1.1  drochner 	}
    144           1.7        ad #endif	/* PCDISPLAY_SOFTCURSOR */
    145           1.1  drochner }
    146           1.1  drochner 
    147           1.5  drochner #if 0
    148           1.5  drochner unsigned int
    149           1.5  drochner pcdisplay_mapchar_simple(id, uni)
    150           1.5  drochner 	void *id;
    151           1.5  drochner 	int uni;
    152           1.4  drochner {
    153           1.5  drochner 	if (uni < 128)
    154           1.5  drochner 		return (uni);
    155           1.5  drochner 
    156           1.5  drochner 	return (1); /* XXX ??? smiley */
    157           1.5  drochner }
    158           1.5  drochner #endif
    159           1.4  drochner 
    160           1.1  drochner void
    161           1.4  drochner pcdisplay_putchar(id, row, col, c, attr)
    162           1.1  drochner 	void *id;
    163           1.1  drochner 	int row, col;
    164           1.4  drochner 	u_int c;
    165           1.1  drochner 	long attr;
    166           1.1  drochner {
    167           1.1  drochner 	struct pcdisplayscreen *scr = id;
    168           1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    169           1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    170  1.25.8.1.4.1    bouyer 	size_t off;
    171           1.1  drochner 
    172           1.1  drochner 	off = row * scr->type->ncols + col;
    173           1.1  drochner 
    174  1.25.8.1.4.1    bouyer 	/* check for bogus row and column sizes */
    175  1.25.8.1.4.1    bouyer 	if (__predict_false(off >= (scr->type->ncols * scr->type->nrows)))
    176  1.25.8.1.4.1    bouyer 		return;
    177  1.25.8.1.4.1    bouyer 
    178           1.4  drochner 	if (scr->active)
    179           1.6  drochner 		bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
    180           1.5  drochner 				  c | (attr << 8));
    181           1.4  drochner 	else
    182           1.5  drochner 		scr->mem[off] = c | (attr << 8);
    183      1.25.8.1      tron 
    184      1.25.8.1      tron 	scr->visibleoffset = scr->dispoffset;
    185           1.1  drochner }
    186           1.1  drochner 
    187           1.1  drochner void
    188           1.1  drochner pcdisplay_copycols(id, row, srccol, dstcol, ncols)
    189           1.1  drochner 	void *id;
    190           1.1  drochner 	int row, srccol, dstcol, ncols;
    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 srcoff, dstoff;
    196           1.1  drochner 
    197           1.1  drochner 	srcoff = dstoff = row * scr->type->ncols;
    198           1.1  drochner 	srcoff += srccol;
    199           1.1  drochner 	dstoff += dstcol;
    200           1.1  drochner 
    201           1.1  drochner 	if (scr->active)
    202           1.6  drochner 		bus_space_copy_region_2(memt, memh,
    203           1.6  drochner 					scr->dispoffset + srcoff * 2,
    204           1.6  drochner 					memh, scr->dispoffset + dstoff * 2,
    205           1.6  drochner 					ncols);
    206           1.1  drochner 	else
    207          1.18   thorpej 		memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2);
    208           1.1  drochner }
    209           1.1  drochner 
    210           1.1  drochner void
    211           1.1  drochner pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
    212           1.1  drochner 	void *id;
    213           1.1  drochner 	int row, startcol, ncols;
    214           1.1  drochner 	long fillattr;
    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 	bus_size_t off;
    220           1.1  drochner 	u_int16_t val;
    221           1.1  drochner 	int i;
    222           1.1  drochner 
    223           1.1  drochner 	off = row * scr->type->ncols + startcol;
    224           1.1  drochner 
    225           1.1  drochner 	val = (fillattr << 8) | ' ';
    226           1.1  drochner 
    227           1.1  drochner 	if (scr->active)
    228           1.6  drochner 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    229           1.6  drochner 				       val, ncols);
    230           1.1  drochner 	else
    231           1.1  drochner 		for (i = 0; i < ncols; i++)
    232           1.1  drochner 			scr->mem[off + i] = val;
    233           1.1  drochner }
    234           1.1  drochner 
    235           1.1  drochner void
    236           1.1  drochner pcdisplay_copyrows(id, srcrow, dstrow, nrows)
    237           1.1  drochner 	void *id;
    238           1.1  drochner 	int srcrow, dstrow, nrows;
    239           1.1  drochner {
    240           1.1  drochner 	struct pcdisplayscreen *scr = id;
    241           1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    242           1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    243           1.1  drochner 	int ncols = scr->type->ncols;
    244           1.1  drochner 	bus_size_t srcoff, dstoff;
    245           1.1  drochner 
    246           1.1  drochner 	srcoff = srcrow * ncols + 0;
    247           1.1  drochner 	dstoff = dstrow * ncols + 0;
    248           1.1  drochner 
    249           1.1  drochner 	if (scr->active)
    250           1.6  drochner 		bus_space_copy_region_2(memt, memh,
    251           1.6  drochner 					scr->dispoffset + srcoff * 2,
    252           1.6  drochner 					memh, scr->dispoffset + dstoff * 2,
    253           1.6  drochner 					nrows * ncols);
    254           1.1  drochner 	else
    255          1.18   thorpej 		memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
    256           1.1  drochner 		      nrows * ncols * 2);
    257           1.1  drochner }
    258           1.1  drochner 
    259           1.1  drochner void
    260           1.1  drochner pcdisplay_eraserows(id, startrow, nrows, fillattr)
    261           1.1  drochner 	void *id;
    262           1.1  drochner 	int startrow, nrows;
    263           1.1  drochner 	long fillattr;
    264           1.1  drochner {
    265           1.1  drochner 	struct pcdisplayscreen *scr = id;
    266           1.1  drochner 	bus_space_tag_t memt = scr->hdl->ph_memt;
    267           1.1  drochner 	bus_space_handle_t memh = scr->hdl->ph_memh;
    268           1.1  drochner 	bus_size_t off, count;
    269           1.1  drochner 	u_int16_t val;
    270          1.25   thorpej 	u_int i;
    271           1.1  drochner 
    272           1.1  drochner 	off = startrow * scr->type->ncols;
    273           1.1  drochner 	count = nrows * scr->type->ncols;
    274           1.1  drochner 
    275           1.1  drochner 	val = (fillattr << 8) | ' ';
    276           1.1  drochner 
    277           1.1  drochner 	if (scr->active)
    278           1.6  drochner 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
    279           1.6  drochner 				       val, count);
    280           1.1  drochner 	else
    281           1.1  drochner 		for (i = 0; i < count; i++)
    282           1.1  drochner 			scr->mem[off + i] = val;
    283          1.21  christos }
    284          1.21  christos 
    285          1.22  christos #ifdef WSDISPLAY_CHARFUNCS
    286          1.21  christos int
    287          1.21  christos pcdisplay_getwschar(id, wschar)
    288          1.21  christos 	void *id;
    289          1.21  christos 	struct wsdisplay_char *wschar;
    290          1.21  christos {
    291          1.21  christos 	struct pcdisplayscreen *scr = id;
    292          1.21  christos 	bus_space_tag_t memt = scr->hdl->ph_memt;
    293          1.21  christos 	bus_space_handle_t memh = scr->hdl->ph_memh;
    294          1.21  christos 	int off;
    295          1.21  christos 	uint16_t chardata;
    296          1.21  christos 	uint8_t attrbyte;
    297          1.21  christos 
    298          1.21  christos 	off = wschar->row * scr->type->ncols + wschar->col;
    299          1.21  christos 	if (off >= scr->type->ncols * scr->type->nrows)
    300          1.21  christos 		return -1;
    301          1.21  christos 
    302          1.21  christos 	if (scr->active)
    303          1.21  christos 		chardata = bus_space_read_2(memt, memh,
    304          1.21  christos 					    scr->dispoffset + off * 2);
    305          1.21  christos 	else
    306          1.21  christos 		chardata = scr->mem[off];
    307          1.21  christos 
    308          1.21  christos 	wschar->letter = (chardata & 0x00FF);
    309          1.21  christos 	wschar->flags = 0;
    310          1.21  christos 	attrbyte = (chardata & 0xFF00) >> 8;
    311          1.21  christos 	if ((attrbyte & 0x08)) wschar->flags |= WSDISPLAY_CHAR_BRIGHT;
    312          1.21  christos 	if ((attrbyte & 0x80)) wschar->flags |= WSDISPLAY_CHAR_BLINK;
    313          1.21  christos 	wschar->foreground = attrbyte & 0x07;
    314          1.21  christos 	wschar->background = (attrbyte >> 4) & 0x07;
    315          1.21  christos 
    316          1.21  christos 	return 0;
    317          1.21  christos }
    318          1.21  christos 
    319          1.21  christos int
    320          1.21  christos pcdisplay_putwschar(id, wschar)
    321          1.21  christos 	void *id;
    322          1.21  christos 	struct wsdisplay_char *wschar;
    323          1.21  christos {
    324          1.21  christos 	struct pcdisplayscreen *scr = id;
    325          1.21  christos 	bus_space_tag_t memt = scr->hdl->ph_memt;
    326          1.21  christos 	bus_space_handle_t memh = scr->hdl->ph_memh;
    327          1.21  christos 	int off;
    328          1.21  christos 	uint16_t chardata;
    329          1.21  christos 	uint8_t attrbyte;
    330          1.21  christos 
    331          1.21  christos 	off = wschar->row * scr->type->ncols + wschar->col;
    332          1.21  christos 	if (off >= (scr->type->ncols * scr->type->nrows))
    333          1.21  christos 		return -1;
    334          1.21  christos 
    335          1.21  christos 	attrbyte = wschar->background & 0x07;
    336          1.21  christos 	if (wschar->flags & WSDISPLAY_CHAR_BLINK) attrbyte |= 0x08;
    337          1.21  christos 	attrbyte <<= 4;
    338          1.21  christos 	attrbyte |= wschar->foreground & 0x07;
    339          1.21  christos 	if (wschar->flags & WSDISPLAY_CHAR_BRIGHT) attrbyte |= 0x08;
    340          1.21  christos 	chardata = (attrbyte << 8) | wschar->letter;
    341          1.21  christos 
    342          1.21  christos 	if (scr->active)
    343          1.21  christos 		bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
    344          1.21  christos 		                  chardata);
    345          1.21  christos 	else
    346          1.21  christos 		scr->mem[off] = chardata;
    347          1.21  christos 
    348          1.21  christos 	return 0;
    349           1.1  drochner }
    350          1.22  christos #endif /* WSDISPLAY_CHARFUNCS */
    351