xref: /original-bsd/sys/hp/dev/ite_subr.c (revision 333da485)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: ite_subr.c 1.4 92/01/21$
13  *
14  *	@(#)ite_subr.c	8.2 (Berkeley) 01/12/94
15  */
16 
17 #include "ite.h"
18 #if NITE > 0
19 
20 #include <sys/param.h>
21 #include <sys/conf.h>
22 #include <sys/proc.h>
23 #include <sys/ioctl.h>
24 #include <sys/tty.h>
25 #include <sys/systm.h>
26 
27 #include <hp/dev/itevar.h>
28 #include <hp/dev/itereg.h>
29 
30 #include <machine/cpu.h>
31 
32 ite_fontinfo(ip)
33 	struct ite_softc *ip;
34 {
35 	u_long fontaddr = getword(ip, getword(ip, FONTROM) + FONTADDR);
36 
37 	ip->ftheight = getbyte(ip, fontaddr + FONTHEIGHT);
38 	ip->ftwidth  = getbyte(ip, fontaddr + FONTWIDTH);
39 	ip->rows     = ip->dheight / ip->ftheight;
40 	ip->cols     = ip->dwidth / ip->ftwidth;
41 
42 	if (ip->fbwidth > ip->dwidth) {
43 		/*
44 		 * Stuff goes to right of display.
45 		 */
46 		ip->fontx    = ip->dwidth;
47 		ip->fonty    = 0;
48 		ip->cpl      = (ip->fbwidth - ip->dwidth) / ip->ftwidth;
49 		ip->cblankx  = ip->dwidth;
50 		ip->cblanky  = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight;
51 	}
52 	else {
53 		/*
54 		 * Stuff goes below the display.
55 		 */
56 		ip->fontx   = 0;
57 		ip->fonty   = ip->dheight;
58 		ip->cpl     = ip->fbwidth / ip->ftwidth;
59 		ip->cblankx = 0;
60 		ip->cblanky = ip->fonty + ((128 / ip->cpl) + 1) * ip->ftheight;
61 	}
62 }
63 
64 ite_fontinit(ip)
65 	register struct ite_softc *ip;
66 {
67 	int bytewidth = (((ip->ftwidth - 1) / 8) + 1);
68 	int glyphsize = bytewidth * ip->ftheight;
69 	u_char fontbuf[500];		/* XXX malloc not initialize yet */
70 	u_char *dp, *fbmem;
71 	int c, i, romp;
72 
73 	romp = getword(ip, getword(ip, FONTROM) + FONTADDR) + FONTDATA;
74 	for (c = 0; c < 128; c++) {
75 		fbmem = (u_char *)
76 		    (FBBASE +
77 		     (ip->fonty + (c / ip->cpl) * ip->ftheight) * ip->fbwidth +
78 		     (ip->fontx + (c % ip->cpl) * ip->ftwidth));
79 		dp = fontbuf;
80 		for (i = 0; i < glyphsize; i++) {
81 			*dp++ = getbyte(ip, romp);
82 			romp += 2;
83 		}
84 		writeglyph(ip, fbmem, fontbuf);
85 	}
86 }
87 
88 /*
89  * Display independent versions of the readbyte and writeglyph routines.
90  */
91 u_char
92 ite_readbyte(ip, disp)
93 	struct ite_softc *ip;
94 	int disp;
95 {
96 	return((u_char) *(((u_char *)ip->regbase) + disp));
97 }
98 
99 ite_writeglyph(ip, fbmem, glyphp)
100 	register struct ite_softc *ip;
101 	register u_char *fbmem, *glyphp;
102 {
103 	register int bn;
104 	int l, b;
105 
106 	for (l = 0; l < ip->ftheight; l++) {
107 		bn = 7;
108 		for (b = 0; b < ip->ftwidth; b++) {
109 			if ((1 << bn) & *glyphp)
110 				*fbmem++ = 1;
111 			else
112 				*fbmem++ = 0;
113 			if (--bn < 0) {
114 				bn = 7;
115 				glyphp++;
116 			}
117 		}
118 		if (bn < 7)
119 			glyphp++;
120 		fbmem -= ip->ftwidth;
121 		fbmem += ip->fbwidth;
122 	}
123 }
124 #endif
125