Home | History | Annotate | Line # | Download | only in ic
vga_subr.c revision 1.6
      1 /* $NetBSD: vga_subr.c,v 1.6 2000/01/25 02:44:03 ad Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1998
      5  *	Matthias Drochner.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed for the NetBSD Project
     18  *	by Matthias Drochner.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 #include <sys/queue.h>
     39 #include <machine/bus.h>
     40 
     41 #include <dev/ic/mc6845reg.h>
     42 #include <dev/ic/pcdisplayvar.h>
     43 #include <dev/ic/vgareg.h>
     44 #include <dev/ic/vgavar.h>
     45 
     46 #include <dev/wscons/wsdisplayvar.h>
     47 
     48 static void fontram __P((struct vga_handle *));
     49 static void textram __P((struct vga_handle *));
     50 
     51 static void
     52 fontram(vh)
     53 	struct vga_handle *vh;
     54 {
     55 	/* program sequencer to access character generator */
     56 
     57 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
     58 	vga_ts_write(vh, wrplmask, 0x04);	/* write to map 2 */
     59 	vga_ts_write(vh, memmode, 0x07);	/* sequential addressing */
     60 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
     61 
     62 	/* program graphics controller to access character generator */
     63 
     64 	vga_gdc_write(vh, rdplanesel, 0x02);	/* select map 2 for cpu reads */
     65 	vga_gdc_write(vh, mode, 0x00);	/* disable odd-even addressing */
     66 	vga_gdc_write(vh, misc, 0x04);	/* map starts at 0xA000 */
     67 }
     68 
     69 static void
     70 textram(vh)
     71 	struct vga_handle *vh;
     72 {
     73 	/* program sequencer to access video ram */
     74 
     75 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
     76 	vga_ts_write(vh, wrplmask, 0x03);	/* write to map 0 & 1 */
     77 	vga_ts_write(vh, memmode, 0x03);	/* odd-even addressing */
     78 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
     79 
     80 	/* program graphics controller for text mode */
     81 
     82 	vga_gdc_write(vh, rdplanesel, 0x00);	/* select map 0 for cpu reads */
     83 	vga_gdc_write(vh, mode, 0x10);		/* enable odd-even addressing */
     84 	/* map starts at 0xb800 or 0xb000 (mono) */
     85 	vga_gdc_write(vh, misc, (vh->vh_mono ? 0x0a : 0x0e));
     86 }
     87 
     88 void
     89 vga_loadchars(vh, fontset, first, num, lpc, data)
     90 	struct vga_handle *vh;
     91 	int fontset, first, num;
     92 	int lpc;
     93 	char *data;
     94 {
     95 	int offset, i, j, s;
     96 
     97 	/* fontset number swizzle done in vga_setfontset() */
     98 	offset = (fontset << 13) | (first << 5);
     99 
    100 	s = splhigh();
    101 	fontram(vh);
    102 
    103 	for (i = 0; i < num; i++)
    104 		for (j = 0; j < lpc; j++)
    105 			bus_space_write_1(vh->vh_memt, vh->vh_allmemh,
    106 					  offset + (i << 5) + j,
    107 					  data[i * lpc + j]);
    108 
    109 	textram(vh);
    110 	splx(s);
    111 }
    112 
    113 void
    114 vga_setfontset(vh, fontset1, fontset2)
    115 	struct vga_handle *vh;
    116 	int fontset1, fontset2;
    117 {
    118 	u_int8_t cmap;
    119 	static u_int8_t cmaptaba[] = {
    120 		0x00, 0x10, 0x01, 0x11,
    121 		0x02, 0x12, 0x03, 0x13
    122 	};
    123 	static u_int8_t cmaptabb[] = {
    124 		0x00, 0x20, 0x04, 0x24,
    125 		0x08, 0x28, 0x0c, 0x2c
    126 	};
    127 
    128 	/* extended font if fontset1 != fontset2 */
    129 	cmap = cmaptaba[fontset1] | cmaptabb[fontset2];
    130 
    131 	vga_ts_write(vh, fontsel, cmap);
    132 }
    133 
    134 void
    135 vga_setscreentype(vh, type)
    136 	struct vga_handle *vh;
    137 	const struct wsscreen_descr *type;
    138 {
    139 	vga_6845_write(vh, maxrow, type->fontheight - 1);
    140 
    141 	/* lo byte */
    142 	vga_6845_write(vh, vde, type->fontheight * type->nrows - 1);
    143 
    144 #ifndef PCDISPLAY_SOFTCURSOR
    145 	/* set cursor to last 2 lines */
    146 	vga_6845_write(vh, curstart, type->fontheight - 2);
    147 	vga_6845_write(vh, curend, type->fontheight - 1);
    148 #endif
    149 	/*
    150 	 * disable colour plane 3 if needed for font selection
    151 	 */
    152 	if (type->capabilities & WSSCREEN_HILIT) {
    153 		/*
    154 		 * these are the screens which don't support
    155 		 * 512-character fonts
    156 		 */
    157 		vga_attr_write(vh, colplen, 0x0f);
    158 	} else
    159 		vga_attr_write(vh, colplen, 0x07);
    160 }
    161