Annotation of sys/arch/hp300/stand/common/ite_subr.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: ite_subr.c,v 1.5 2006/08/17 06:31:10 miod Exp $ */
2: /* $NetBSD: ite_subr.c,v 1.8 1996/03/03 04:23:40 thorpej Exp $ */
3:
4: /*
5: * Copyright (c) 1988 University of Utah.
6: * Copyright (c) 1990, 1993
7: * The Regents of the University of California. All rights reserved.
8: *
9: * This code is derived from software contributed to Berkeley by
10: * the Systems Programming Group of the University of Utah Computer
11: * Science Department.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. Neither the name of the University nor the names of its contributors
22: * may be used to endorse or promote products derived from this software
23: * without specific prior written permission.
24: *
25: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35: * SUCH DAMAGE.
36: *
37: * from: Utah $Hdr: ite_subr.c 1.2 92/01/20$
38: *
39: * @(#)ite_subr.c 8.1 (Berkeley) 6/10/93
40: */
41:
42: #ifdef ITECONSOLE
43:
44: #include <sys/param.h>
45:
46: #include "samachdep.h"
47: #include "itevar.h"
48: #include "itereg.h"
49:
50: #define getbyte(ip, offset) \
51: *(((u_char *)(ip)->regbase) + (offset))
52:
53: #define getword(ip, offset) \
54: ((getbyte(ip, offset) << 8) | getbyte(ip, (offset) + 2))
55:
56: u_char ite_readbyte(struct ite_data *, int);
57: void ite_writeglyph(struct ite_data *, u_char *, u_char *);
58:
59: void
60: ite_fontinfo(struct ite_data *ip)
61: {
62: u_long fontaddr = getword(ip, getword(ip, FONTROM) + FONTADDR);
63:
64: ip->ftheight = getbyte(ip, fontaddr + FONTHEIGHT);
65: ip->ftwidth = getbyte(ip, fontaddr + FONTWIDTH);
66: ip->rows = ip->dheight / ip->ftheight;
67: ip->cols = ip->dwidth / ip->ftwidth;
68:
69: if (ip->fbwidth > ip->dwidth) {
70: /*
71: * Stuff goes to right of display.
72: */
73: ip->fontx = ip->dwidth;
74: ip->fonty = 0;
75: ip->cpl = (ip->fbwidth - ip->dwidth) / ip->ftwidth;
76: ip->cblankx = ip->dwidth;
77: ip->cblanky = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight;
78: } else {
79: /*
80: * Stuff goes below the display.
81: */
82: ip->fontx = 0;
83: ip->fonty = ip->dheight;
84: ip->cpl = ip->fbwidth / ip->ftwidth;
85: ip->cblankx = 0;
86: ip->cblanky = ip->fonty + ((128 / ip->cpl) + 1) * ip->ftheight;
87: }
88: }
89:
90: void
91: ite_fontinit1bpp(struct ite_data *ip)
92: {
93: u_char *fbmem, *dp;
94: int c, l, b;
95: int stride, width;
96:
97: dp = (u_char *)(getword(ip, getword(ip, FONTROM) + FONTADDR) +
98: ip->regbase) + FONTDATA;
99: stride = ip->fbwidth >> 3;
100: width = (ip->ftwidth + 7) / 8;
101:
102: for (c = 0; c < 128; c++) {
103: fbmem = (u_char *)FBBASE +
104: (ip->fonty + (c / ip->cpl) * ip->ftheight) * stride;
105: fbmem += (ip->fontx >> 3) + (c % ip->cpl) * width;
106: for (l = 0; l < ip->ftheight; l++) {
107: for (b = 0; b < width; b++) {
108: *fbmem++ = *dp;
109: dp += 2;
110: }
111: fbmem -= width;
112: fbmem += stride;
113: }
114: }
115: }
116:
117: void
118: ite_fontinit8bpp(struct ite_data *ip)
119: {
120: int bytewidth = (((ip->ftwidth - 1) / 8) + 1);
121: int glyphsize = bytewidth * ip->ftheight;
122: u_char fontbuf[500];
123: u_char *dp, *fbmem;
124: int c, i, romp;
125:
126: romp = getword(ip, getword(ip, FONTROM) + FONTADDR) + FONTDATA;
127: for (c = 0; c < 128; c++) {
128: fbmem = (u_char *)(FBBASE +
129: (ip->fonty + (c / ip->cpl) * ip->ftheight) * ip->fbwidth +
130: (ip->fontx + (c % ip->cpl) * ip->ftwidth));
131: dp = fontbuf;
132: for (i = 0; i < glyphsize; i++) {
133: *dp++ = getbyte(ip, romp);
134: romp += 2;
135: }
136: ite_writeglyph(ip, fbmem, fontbuf);
137: }
138: }
139:
140: void
141: ite_writeglyph(struct ite_data *ip, u_char *fbmem, u_char *glyphp)
142: {
143: int bn;
144: int l, b;
145:
146: for (l = 0; l < ip->ftheight; l++) {
147: bn = 7;
148: for (b = 0; b < ip->ftwidth; b++) {
149: if ((1 << bn) & *glyphp)
150: *fbmem++ = 1;
151: else
152: *fbmem++ = 0;
153: if (--bn < 0) {
154: bn = 7;
155: glyphp++;
156: }
157: }
158: if (bn < 7)
159: glyphp++;
160: fbmem -= ip->ftwidth;
161: fbmem += ip->fbwidth;
162: }
163: }
164:
165: /*
166: * The cursor is just an inverted space.
167: */
168: #define flip_cursor(ip) \
169: (*ip->bmv)(ip, ip->cblanky, ip->cblankx, ip->cursory * ip->ftheight, \
170: ip->cursorx * ip->ftwidth, ip->ftheight, ip->ftwidth, RR_XOR)
171:
172: void
173: ite_dio_cursor(struct ite_data *ip, int flag)
174: {
175: switch (flag) {
176: case MOVE_CURSOR:
177: flip_cursor(ip);
178: /* FALLTHROUGH */
179: case DRAW_CURSOR:
180: ip->cursorx = ip->curx;
181: ip->cursory = ip->cury;
182: /* FALLTHROUGH */
183: default:
184: flip_cursor(ip);
185: break;
186: }
187: }
188:
189: void
190: ite_dio_putc1bpp(struct ite_data *ip, int c, int dy, int dx)
191: {
192: ite_dio_windowmove1bpp(ip, charY(ip, c), charX1bpp(ip, c),
193: dy * ip->ftheight, dx * ip->ftwidth,
194: ip->ftheight, ip->ftwidth, RR_COPY);
195: }
196:
197: void
198: ite_dio_putc8bpp(struct ite_data *ip, int c, int dy, int dx)
199: {
200: (*ip->bmv)(ip, charY(ip, c), charX(ip, c),
201: dy * ip->ftheight, dx * ip->ftwidth,
202: ip->ftheight, ip->ftwidth, RR_COPY);
203: }
204:
205: void
206: ite_dio_clear(struct ite_data *ip, int sy, int sx, int h, int w)
207: {
208: (*ip->bmv)(ip, sy * ip->ftheight, sx * ip->ftwidth,
209: sy * ip->ftheight, sx * ip->ftwidth,
210: h * ip->ftheight, w * ip->ftwidth, RR_CLEAR);
211: }
212:
213: void
214: ite_dio_scroll(struct ite_data *ip)
215: {
216: flip_cursor(ip);
217:
218: (*ip->bmv)(ip, ip->ftheight, 0, 0, 0, (ip->rows - 1) * ip->ftheight,
219: ip->cols * ip->ftwidth, RR_COPY);
220: }
221:
222: #include "maskbits.h"
223:
224: /* NOTE:
225: * the first element in starttab could be 0xffffffff. making it 0
226: * lets us deal with a full first word in the middle loop, rather
227: * than having to do the multiple reads and masks that we'd
228: * have to do if we thought it was partial.
229: */
230: int starttab[32] = {
231: 0x00000000,
232: 0x7FFFFFFF,
233: 0x3FFFFFFF,
234: 0x1FFFFFFF,
235: 0x0FFFFFFF,
236: 0x07FFFFFF,
237: 0x03FFFFFF,
238: 0x01FFFFFF,
239: 0x00FFFFFF,
240: 0x007FFFFF,
241: 0x003FFFFF,
242: 0x001FFFFF,
243: 0x000FFFFF,
244: 0x0007FFFF,
245: 0x0003FFFF,
246: 0x0001FFFF,
247: 0x0000FFFF,
248: 0x00007FFF,
249: 0x00003FFF,
250: 0x00001FFF,
251: 0x00000FFF,
252: 0x000007FF,
253: 0x000003FF,
254: 0x000001FF,
255: 0x000000FF,
256: 0x0000007F,
257: 0x0000003F,
258: 0x0000001F,
259: 0x0000000F,
260: 0x00000007,
261: 0x00000003,
262: 0x00000001
263: };
264:
265: int endtab[32] = {
266: 0x00000000,
267: 0x80000000,
268: 0xC0000000,
269: 0xE0000000,
270: 0xF0000000,
271: 0xF8000000,
272: 0xFC000000,
273: 0xFE000000,
274: 0xFF000000,
275: 0xFF800000,
276: 0xFFC00000,
277: 0xFFE00000,
278: 0xFFF00000,
279: 0xFFF80000,
280: 0xFFFC0000,
281: 0xFFFE0000,
282: 0xFFFF0000,
283: 0xFFFF8000,
284: 0xFFFFC000,
285: 0xFFFFE000,
286: 0xFFFFF000,
287: 0xFFFFF800,
288: 0xFFFFFC00,
289: 0xFFFFFE00,
290: 0xFFFFFF00,
291: 0xFFFFFF80,
292: 0xFFFFFFC0,
293: 0xFFFFFFE0,
294: 0xFFFFFFF0,
295: 0xFFFFFFF8,
296: 0xFFFFFFFC,
297: 0xFFFFFFFE
298: };
299:
300: void
301: ite_dio_windowmove1bpp(struct ite_data *ip, int sy, int sx, int dy, int dx,
302: int h, int w, int func)
303: {
304: int width; /* add to get to same position in next line */
305:
306: unsigned int *psrcLine, *pdstLine;
307: /* pointers to line with current src and dst */
308: unsigned int *psrc; /* pointer to current src longword */
309: unsigned int *pdst; /* pointer to current dst longword */
310:
311: /* following used for looping through a line */
312: unsigned int startmask, endmask; /* masks for writing ends of dst */
313: int nlMiddle; /* whole longwords in dst */
314: int nl; /* temp copy of nlMiddle */
315: unsigned int tmpSrc; /* place to store full source word */
316: int xoffSrc; /* offset (>= 0, < 32) from which to
317: fetch whole longwords fetched
318: in src */
319: int nstart; /* number of ragged bits at start of dst */
320: int nend; /* number of ragged bits at end of dst */
321: int srcStartOver; /* pulling nstart bits from src
322: overflows into the next word? */
323:
324: if (h == 0 || w == 0)
325: return;
326:
327: width = ip->fbwidth >> 5;
328: psrcLine = ((unsigned int *) ip->fbbase) + (sy * width);
329: pdstLine = ((unsigned int *) ip->fbbase) + (dy * width);
330:
331: /* x direction doesn't matter for < 1 longword */
332: if (w <= 32) {
333: int srcBit, dstBit; /* bit offset of src and dst */
334:
335: pdstLine += (dx >> 5);
336: psrcLine += (sx >> 5);
337: psrc = psrcLine;
338: pdst = pdstLine;
339:
340: srcBit = sx & 0x1f;
341: dstBit = dx & 0x1f;
342:
343: while (h--) {
344: getandputrop(psrc, srcBit, dstBit, w, pdst, func);
345: pdst += width;
346: psrc += width;
347: }
348: } else {
349: maskbits(dx, w, startmask, endmask, nlMiddle);
350: if (startmask)
351: nstart = 32 - (dx & 0x1f);
352: else
353: nstart = 0;
354: if (endmask)
355: nend = (dx + w) & 0x1f;
356: else
357: nend = 0;
358:
359: xoffSrc = ((sx & 0x1f) + nstart) & 0x1f;
360: srcStartOver = ((sx & 0x1f) + nstart) > 31;
361:
362: pdstLine += (dx >> 5);
363: psrcLine += (sx >> 5);
364:
365: while (h--) {
366: psrc = psrcLine;
367: pdst = pdstLine;
368:
369: if (startmask) {
370: getandputrop(psrc, (sx & 0x1f), (dx & 0x1f),
371: nstart, pdst, func);
372: pdst++;
373: if (srcStartOver)
374: psrc++;
375: }
376:
377: /* special case for aligned operations */
378: if (xoffSrc == 0) {
379: nl = nlMiddle;
380: while (nl--) {
381: DoRop (*pdst, func, *psrc++, *pdst);
382: pdst++;
383: }
384: } else {
385: nl = nlMiddle + 1;
386: while (--nl) {
387: getunalignedword (psrc, xoffSrc,
388: tmpSrc);
389: DoRop (*pdst, func, tmpSrc, *pdst);
390: pdst++;
391: psrc++;
392: }
393: }
394:
395: if (endmask) {
396: getandputrop0(psrc, xoffSrc, nend, pdst, func);
397: }
398:
399: pdstLine += width;
400: psrcLine += width;
401: }
402: }
403: }
404: #endif
CVSweb