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