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