diofb_mono.c revision 1.2.6.2 1 1.2.6.2 jruoho /* $NetBSD: diofb_mono.c,v 1.2.6.2 2011/06/06 09:05:35 jruoho Exp $ */
2 1.2.6.2 jruoho /* $OpenBSD: diofb_mono.c,v 1.3 2006/08/11 18:33:13 miod Exp $ */
3 1.2.6.2 jruoho
4 1.2.6.2 jruoho /*
5 1.2.6.2 jruoho * Copyright (c) 2005, Miodrag Vallat.
6 1.2.6.2 jruoho * All rights reserved.
7 1.2.6.2 jruoho *
8 1.2.6.2 jruoho * Redistribution and use in source and binary forms, with or without
9 1.2.6.2 jruoho * modification, are permitted provided that the following conditions
10 1.2.6.2 jruoho * are met:
11 1.2.6.2 jruoho * 1. Redistributions of source code must retain the above copyright
12 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer.
13 1.2.6.2 jruoho * 2. Redistributions in binary form must reproduce the above copyright
14 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer in the
15 1.2.6.2 jruoho * documentation and/or other materials provided with the distribution.
16 1.2.6.2 jruoho *
17 1.2.6.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.2.6.2 jruoho * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.2.6.2 jruoho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.2.6.2 jruoho * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 1.2.6.2 jruoho * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.2.6.2 jruoho * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.2.6.2 jruoho * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.2.6.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.2.6.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 1.2.6.2 jruoho * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.2.6.2 jruoho * POSSIBILITY OF SUCH DAMAGE.
28 1.2.6.2 jruoho *
29 1.2.6.2 jruoho */
30 1.2.6.2 jruoho /*-
31 1.2.6.2 jruoho * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
32 1.2.6.2 jruoho * All rights reserved.
33 1.2.6.2 jruoho *
34 1.2.6.2 jruoho * This code is derived from software contributed to The NetBSD Foundation
35 1.2.6.2 jruoho * by Jason R. Thorpe.
36 1.2.6.2 jruoho *
37 1.2.6.2 jruoho * Redistribution and use in source and binary forms, with or without
38 1.2.6.2 jruoho * modification, are permitted provided that the following conditions
39 1.2.6.2 jruoho * are met:
40 1.2.6.2 jruoho * 1. Redistributions of source code must retain the above copyright
41 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer.
42 1.2.6.2 jruoho * 2. Redistributions in binary form must reproduce the above copyright
43 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer in the
44 1.2.6.2 jruoho * documentation and/or other materials provided with the distribution.
45 1.2.6.2 jruoho *
46 1.2.6.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
47 1.2.6.2 jruoho * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
48 1.2.6.2 jruoho * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49 1.2.6.2 jruoho * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
50 1.2.6.2 jruoho * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 1.2.6.2 jruoho * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 1.2.6.2 jruoho * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 1.2.6.2 jruoho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 1.2.6.2 jruoho * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 1.2.6.2 jruoho * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 1.2.6.2 jruoho * POSSIBILITY OF SUCH DAMAGE.
57 1.2.6.2 jruoho */
58 1.2.6.2 jruoho
59 1.2.6.2 jruoho /*
60 1.2.6.2 jruoho * Copyright (c) 1991 University of Utah.
61 1.2.6.2 jruoho * Copyright (c) 1990, 1993
62 1.2.6.2 jruoho * The Regents of the University of California. All rights reserved.
63 1.2.6.2 jruoho *
64 1.2.6.2 jruoho * This code is derived from software contributed to Berkeley by
65 1.2.6.2 jruoho * the Systems Programming Group of the University of Utah Computer
66 1.2.6.2 jruoho * Science Department and Mark Davies of the Department of Computer
67 1.2.6.2 jruoho * Science, Victoria University of Wellington, New Zealand.
68 1.2.6.2 jruoho *
69 1.2.6.2 jruoho * Redistribution and use in source and binary forms, with or without
70 1.2.6.2 jruoho * modification, are permitted provided that the following conditions
71 1.2.6.2 jruoho * are met:
72 1.2.6.2 jruoho * 1. Redistributions of source code must retain the above copyright
73 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer.
74 1.2.6.2 jruoho * 2. Redistributions in binary form must reproduce the above copyright
75 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer in the
76 1.2.6.2 jruoho * documentation and/or other materials provided with the distribution.
77 1.2.6.2 jruoho * 3. Neither the name of the University nor the names of its contributors
78 1.2.6.2 jruoho * may be used to endorse or promote products derived from this software
79 1.2.6.2 jruoho * without specific prior written permission.
80 1.2.6.2 jruoho *
81 1.2.6.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
82 1.2.6.2 jruoho * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 1.2.6.2 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84 1.2.6.2 jruoho * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
85 1.2.6.2 jruoho * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 1.2.6.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 1.2.6.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 1.2.6.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 1.2.6.2 jruoho * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 1.2.6.2 jruoho * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91 1.2.6.2 jruoho * SUCH DAMAGE.
92 1.2.6.2 jruoho *
93 1.2.6.2 jruoho * from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
94 1.2.6.2 jruoho *
95 1.2.6.2 jruoho * @(#)grf_hy.c 8.4 (Berkeley) 1/12/94
96 1.2.6.2 jruoho */
97 1.2.6.2 jruoho
98 1.2.6.2 jruoho /*
99 1.2.6.2 jruoho * Graphics routines for real 1bpp frame buffers (i.e. pixels not being
100 1.2.6.2 jruoho * byte-addressed)
101 1.2.6.2 jruoho */
102 1.2.6.2 jruoho
103 1.2.6.2 jruoho #include <sys/param.h>
104 1.2.6.2 jruoho #include <sys/systm.h>
105 1.2.6.2 jruoho #include <sys/bus.h>
106 1.2.6.2 jruoho
107 1.2.6.2 jruoho #include <dev/wscons/wsconsio.h>
108 1.2.6.2 jruoho #include <dev/wscons/wsdisplayvar.h>
109 1.2.6.2 jruoho #include <dev/rasops/rasops.h>
110 1.2.6.2 jruoho
111 1.2.6.2 jruoho #include <hp300/dev/diofbreg.h>
112 1.2.6.2 jruoho #include <hp300/dev/diofbvar.h>
113 1.2.6.2 jruoho
114 1.2.6.2 jruoho #include <dev/rasops/rasops_masks.h>
115 1.2.6.2 jruoho #include <hp300/dev/maskbits.h>
116 1.2.6.2 jruoho
117 1.2.6.2 jruoho int
118 1.2.6.2 jruoho diofb_mono_windowmove(struct diofb *fb, uint16_t sx, uint16_t sy,
119 1.2.6.2 jruoho uint16_t dx, uint16_t dy, uint16_t cx, uint16_t cy, int16_t rop,
120 1.2.6.2 jruoho int16_t planemask /* ignored */)
121 1.2.6.2 jruoho {
122 1.2.6.2 jruoho int width; /* add to get to same position in next line */
123 1.2.6.2 jruoho
124 1.2.6.2 jruoho unsigned int *psrcLine, *pdstLine;
125 1.2.6.2 jruoho /* pointers to line with current src and dst */
126 1.2.6.2 jruoho unsigned int *psrc; /* pointer to current src longword */
127 1.2.6.2 jruoho unsigned int *pdst; /* pointer to current dst longword */
128 1.2.6.2 jruoho
129 1.2.6.2 jruoho /* following used for looping through a line */
130 1.2.6.2 jruoho unsigned int startmask, endmask; /* masks for writing ends of dst */
131 1.2.6.2 jruoho int nlMiddle; /* whole longwords in dst */
132 1.2.6.2 jruoho int nl; /* temp copy of nlMiddle */
133 1.2.6.2 jruoho int xoffSrc; /* offset (>= 0, < 32) from which to
134 1.2.6.2 jruoho fetch whole longwords fetched in src */
135 1.2.6.2 jruoho int nstart; /* number of ragged bits at start of dst */
136 1.2.6.2 jruoho int nend; /* number of ragged bits at end of dst */
137 1.2.6.2 jruoho int srcStartOver; /* pulling nstart bits from src
138 1.2.6.2 jruoho overflows into the next word? */
139 1.2.6.2 jruoho
140 1.2.6.2 jruoho width = fb->fbwidth >> 5;
141 1.2.6.2 jruoho
142 1.2.6.2 jruoho if (sy < dy) { /* start at last scanline of rectangle */
143 1.2.6.2 jruoho psrcLine = ((u_int *)fb->fbkva) + ((sy + cy - 1) * width);
144 1.2.6.2 jruoho pdstLine = ((u_int *)fb->fbkva) + ((dy + cy - 1) * width);
145 1.2.6.2 jruoho width = -width;
146 1.2.6.2 jruoho } else { /* start at first scanline */
147 1.2.6.2 jruoho psrcLine = ((u_int *)fb->fbkva) + (sy * width);
148 1.2.6.2 jruoho pdstLine = ((u_int *)fb->fbkva) + (dy * width);
149 1.2.6.2 jruoho }
150 1.2.6.2 jruoho
151 1.2.6.2 jruoho /* x direction doesn't matter for < 1 longword */
152 1.2.6.2 jruoho if (cx <= 32) {
153 1.2.6.2 jruoho int srcBit, dstBit; /* bit offset of src and dst */
154 1.2.6.2 jruoho
155 1.2.6.2 jruoho pdstLine += (dx >> 5);
156 1.2.6.2 jruoho psrcLine += (sx >> 5);
157 1.2.6.2 jruoho psrc = psrcLine;
158 1.2.6.2 jruoho pdst = pdstLine;
159 1.2.6.2 jruoho
160 1.2.6.2 jruoho srcBit = sx & 0x1f;
161 1.2.6.2 jruoho dstBit = dx & 0x1f;
162 1.2.6.2 jruoho
163 1.2.6.2 jruoho while (cy--) {
164 1.2.6.2 jruoho getandputrop(psrc, srcBit, dstBit, cx, pdst, rop);
165 1.2.6.2 jruoho pdst += width;
166 1.2.6.2 jruoho psrc += width;
167 1.2.6.2 jruoho }
168 1.2.6.2 jruoho } else {
169 1.2.6.2 jruoho maskbits(dx, cx, startmask, endmask, nlMiddle);
170 1.2.6.2 jruoho if (startmask)
171 1.2.6.2 jruoho nstart = 32 - (dx & 0x1f);
172 1.2.6.2 jruoho else
173 1.2.6.2 jruoho nstart = 0;
174 1.2.6.2 jruoho if (endmask)
175 1.2.6.2 jruoho nend = (dx + cx) & 0x1f;
176 1.2.6.2 jruoho else
177 1.2.6.2 jruoho nend = 0;
178 1.2.6.2 jruoho
179 1.2.6.2 jruoho xoffSrc = ((sx & 0x1f) + nstart) & 0x1f;
180 1.2.6.2 jruoho srcStartOver = ((sx & 0x1f) + nstart) > 31;
181 1.2.6.2 jruoho
182 1.2.6.2 jruoho if (sx >= dx) { /* move left to right */
183 1.2.6.2 jruoho pdstLine += (dx >> 5);
184 1.2.6.2 jruoho psrcLine += (sx >> 5);
185 1.2.6.2 jruoho
186 1.2.6.2 jruoho while (cy--) {
187 1.2.6.2 jruoho psrc = psrcLine;
188 1.2.6.2 jruoho pdst = pdstLine;
189 1.2.6.2 jruoho
190 1.2.6.2 jruoho if (startmask) {
191 1.2.6.2 jruoho getandputrop(psrc, (sx & 0x1f),
192 1.2.6.2 jruoho (dx & 0x1f), nstart, pdst, rop);
193 1.2.6.2 jruoho pdst++;
194 1.2.6.2 jruoho if (srcStartOver)
195 1.2.6.2 jruoho psrc++;
196 1.2.6.2 jruoho }
197 1.2.6.2 jruoho
198 1.2.6.2 jruoho /* special case for aligned operations */
199 1.2.6.2 jruoho if (xoffSrc == 0) {
200 1.2.6.2 jruoho nl = nlMiddle;
201 1.2.6.2 jruoho while (nl--) {
202 1.2.6.2 jruoho if (rop == RR_CLEAR)
203 1.2.6.2 jruoho *pdst = 0;
204 1.2.6.2 jruoho else
205 1.2.6.2 jruoho *pdst = *psrc;
206 1.2.6.2 jruoho psrc++;
207 1.2.6.2 jruoho pdst++;
208 1.2.6.2 jruoho }
209 1.2.6.2 jruoho } else {
210 1.2.6.2 jruoho nl = nlMiddle + 1;
211 1.2.6.2 jruoho while (--nl) {
212 1.2.6.2 jruoho if (rop == RR_CLEAR)
213 1.2.6.2 jruoho *pdst = 0;
214 1.2.6.2 jruoho else
215 1.2.6.2 jruoho getunalignedword(psrc,
216 1.2.6.2 jruoho xoffSrc, *pdst);
217 1.2.6.2 jruoho pdst++;
218 1.2.6.2 jruoho psrc++;
219 1.2.6.2 jruoho }
220 1.2.6.2 jruoho }
221 1.2.6.2 jruoho
222 1.2.6.2 jruoho if (endmask) {
223 1.2.6.2 jruoho getandputrop(psrc, xoffSrc, 0, nend,
224 1.2.6.2 jruoho pdst, rop);
225 1.2.6.2 jruoho }
226 1.2.6.2 jruoho
227 1.2.6.2 jruoho pdstLine += width;
228 1.2.6.2 jruoho psrcLine += width;
229 1.2.6.2 jruoho }
230 1.2.6.2 jruoho } else { /* move right to left */
231 1.2.6.2 jruoho pdstLine += ((dx + cx) >> 5);
232 1.2.6.2 jruoho psrcLine += ((sx + cx) >> 5);
233 1.2.6.2 jruoho /*
234 1.2.6.2 jruoho * If fetch of last partial bits from source crosses
235 1.2.6.2 jruoho * a longword boundary, start at the previous longword
236 1.2.6.2 jruoho */
237 1.2.6.2 jruoho if (xoffSrc + nend >= 32)
238 1.2.6.2 jruoho --psrcLine;
239 1.2.6.2 jruoho
240 1.2.6.2 jruoho while (cy--) {
241 1.2.6.2 jruoho psrc = psrcLine;
242 1.2.6.2 jruoho pdst = pdstLine;
243 1.2.6.2 jruoho
244 1.2.6.2 jruoho if (endmask) {
245 1.2.6.2 jruoho getandputrop(psrc, xoffSrc, 0, nend,
246 1.2.6.2 jruoho pdst, rop);
247 1.2.6.2 jruoho }
248 1.2.6.2 jruoho
249 1.2.6.2 jruoho nl = nlMiddle + 1;
250 1.2.6.2 jruoho while (--nl) {
251 1.2.6.2 jruoho --psrc;
252 1.2.6.2 jruoho --pdst;
253 1.2.6.2 jruoho if (rop == RR_CLEAR)
254 1.2.6.2 jruoho *pdst = 0;
255 1.2.6.2 jruoho else
256 1.2.6.2 jruoho getunalignedword(psrc, xoffSrc,
257 1.2.6.2 jruoho *pdst);
258 1.2.6.2 jruoho }
259 1.2.6.2 jruoho
260 1.2.6.2 jruoho if (startmask) {
261 1.2.6.2 jruoho if (srcStartOver)
262 1.2.6.2 jruoho --psrc;
263 1.2.6.2 jruoho --pdst;
264 1.2.6.2 jruoho getandputrop(psrc, (sx & 0x1f),
265 1.2.6.2 jruoho (dx & 0x1f), nstart, pdst, rop);
266 1.2.6.2 jruoho }
267 1.2.6.2 jruoho
268 1.2.6.2 jruoho pdstLine += width;
269 1.2.6.2 jruoho psrcLine += width;
270 1.2.6.2 jruoho }
271 1.2.6.2 jruoho }
272 1.2.6.2 jruoho }
273 1.2.6.2 jruoho
274 1.2.6.2 jruoho return 0;
275 1.2.6.2 jruoho }
276