Home | History | Annotate | Line # | Download | only in ic
vga_subr.c revision 1.1
      1 /* $NetBSD: vga_subr.c,v 1.1 1998/03/22 15:11:49 drochner 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/vgareg.h>
     42 #include <dev/ic/vgavar.h>
     43 
     44 #include <dev/wscons/wsdisplayvar.h>
     45 
     46 static void fontram __P((struct vga_handle *));
     47 static void textram __P((struct vga_handle *));
     48 
     49 static void
     50 fontram(vh)
     51 	struct vga_handle *vh;
     52 {
     53 	/* program sequencer to access character generator */
     54 
     55 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
     56 	vga_ts_write(vh, wrplmask, 0x04);	/* write to map 2 */
     57 	vga_ts_write(vh, memmode, 0x07);	/* sequential addressing */
     58 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
     59 
     60 	/* program graphics controller to access character generator */
     61 
     62 	vga_gdc_write(vh, rdplanesel, 0x02);	/* select map 2 for cpu reads */
     63 	vga_gdc_write(vh, mode, 0x00);	/* disable odd-even addressing */
     64 	vga_gdc_write(vh, misc, 0x04);	/* map starts at 0xA000 */
     65 }
     66 
     67 static void
     68 textram(vh)
     69 	struct vga_handle *vh;
     70 {
     71 	/* program sequencer to access video ram */
     72 
     73 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
     74 	vga_ts_write(vh, wrplmask, 0x03);	/* write to map 0 & 1 */
     75 	vga_ts_write(vh, memmode, 0x03);	/* odd-even addressing */
     76 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
     77 
     78 	/* program graphics controller for text mode */
     79 
     80 	vga_gdc_write(vh, rdplanesel, 0x00);	/* select map 0 for cpu reads */
     81 	vga_gdc_write(vh, mode, 0x10);		/* enable odd-even addressing */
     82 	/* map starts at 0xb800 or 0xb000 (mono) */
     83 	vga_gdc_write(vh, misc, (vh->mono ? 0x0a : 0x0e));
     84 }
     85 
     86 void
     87 vga_loadchars(vh, fontset, first, num, lpc, data)
     88 	struct vga_handle *vh;
     89 	int fontset, first, num;
     90 	int lpc;
     91 	char *data;
     92 {
     93 	int offset, i, j, s;
     94 
     95 	/* fontset number swizzle done in vga_setfontset() */
     96 	offset = (fontset << 13) | (first << 5);
     97 
     98 	s = splhigh();
     99 	fontram(vh);
    100 
    101 	for (i = 0; i < num; i++)
    102 		for (j = 0; j < lpc; j++)
    103 			bus_space_write_1(vh->vh_memt, vh->vh_allmemh,
    104 					  offset + (i << 5) + j,
    105 					  data[i * lpc + j]);
    106 
    107 	textram(vh);
    108 	splx(s);
    109 }
    110 
    111 void
    112 vga_setfontset(vh, fontset)
    113 	struct vga_handle *vh;
    114 	int fontset;
    115 {
    116 	u_int8_t cmap;
    117 	static u_int8_t cmaptaba[] = {
    118 		0x00, 0x10, 0x02, 0x12,
    119 		0x01, 0x11, 0x03, 0x13
    120 	};
    121 	static u_int8_t cmaptabb[] = {
    122 		0x00, 0x20, 0x08, 0x28,
    123 		0x04, 0x24, 0x0c, 0x2c
    124 	};
    125 
    126 	/* no extended fonts for now */
    127 	cmap = cmaptaba[fontset] | cmaptabb[fontset];
    128 
    129 	vga_ts_write(vh, fontsel, cmap);
    130 }
    131 
    132 void
    133 vga_setscreentype(vh, type)
    134 	struct vga_handle *vh;
    135 	const struct wsscreen_descr *type;
    136 {
    137 	vga_6845_write(vh, maxrow, type->fontheight - 1);
    138 
    139 	/* lo byte */
    140 	vga_6845_write(vh, vde, type->fontheight * type->nrows - 1);
    141 
    142 	/* set cursor to last 2 lines */
    143 	vga_6845_write(vh, curstart, type->fontheight - 2);
    144 	vga_6845_write(vh, curend, type->fontheight - 1);
    145 }
    146